Search code examples
rubypage-object-gem

Which is new method to set value for text field


I use: self.txtLogin_element.when_present.set(email)

But when it executes I get a warning:

*** You are calling a method named set at C:/login_page.rb:12:in `specify_email'. *** This method does not exist in page-object so it is being passed to the driver. *** This feature will be removed in the near future.

How to specify a new variant with when_present

Variants:

self.txtLogin_element.when_present = email self.txtLogin.when_present.set(email)

do not work.


Solution

  • Assuming that txtLogin_element is a text field (PageObject::Elements::TextField), there is no set method. The Page-Object gem sets text fields via the value= method instead. Therefore, to remove the warning, use:

    self.txtLogin_element.when_present.value = email
    

    If you have made the switch to Page-Object v2.0 and therefore Watir v6.0, when_present is no longer needed. Watir now waits for elements to be present before interacting with them. You can now simply do:

    self.txtLogin_element.value = email
    

    Which ultimately means that you can just use the methods generated by the accessor:

    self.txtLogin = email