yudi2312 yudi2312 - 2 months ago 7x
Ruby Question

Create PageObject elements inside a function

I am trying to create page object elements inside a function so that i could change the element property depending upon the parameter.

class SomePage
include PageObject

def create_element(x)
div(:my_element, :id => "something-{x}")


But when i call this function i am getting below error:

undefined method `div' for #<SomePage:0x35a6be8> (NoMethodError).

If i write the same code with a fixed property value, it works fine. But i need to create elements in the above way using a function.


Your method should look like this:

def create_element(x)
  div_element(:id => "something-#{x}")

Method #div is Accessor. It only defines methods for you. It's been designed to be used in the field of a class.