yudi2312 yudi2312 - 1 year ago 81
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download