yudi2312
yudi2312

Reputation: 323

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}")
  end

end

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.

Upvotes: 0

Views: 116

Answers (1)

Evmorov
Evmorov

Reputation: 1219

Your method should look like this:

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

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

Upvotes: 1

Related Questions