Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method 'type' when the retrieved adjacent elements includes inputs #478

Open
jkotests opened this issue Feb 5, 2019 · 1 comment
Labels

Comments

@jkotests
Copy link
Collaborator

jkotests commented Feb 5, 2019

For example, given the following page, which has an input adjacent to a div:

<html>
  <body>
    <label id="abc">a</label>
    <input type="checkbox">
  </body>
</html>

An exception will occur when trying to get the adjacent elements:

class MyPage
	include PageObject

	label(:abc, id: 'abc')
end

page = MyPage.new(browser)
page.abc_element.following_siblings
#=> C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:844:in `method_missing': undefined method `type' for #<Watir::Label: located: true; {:id=>"abc", :tag_name=>"label"}> (NoMethodError)
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/page-object-2.2.5/lib/page-object/elements/element.rb:185:in `pageobject_wrapper'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/page-object-2.2.5/lib/page-object/elements/element.rb:131:in `block in following_siblings'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/element_collection.rb:32:in `each'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/element_collection.rb:32:in `each'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/page-object-2.2.5/lib/page-object/elements/element.rb:131:in `collect'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/page-object-2.2.5/lib/page-object/elements/element.rb:131:in `following_siblings'
@jkotests
Copy link
Collaborator Author

jkotests commented Feb 5, 2019

Verified with Page-Object v2.2.5 and Watir v6.16.5. From code inspection, would have existed since Page-Object v2.2.3.

The problem appears to be in the pageobject_wrapper:

def pageobject_wrapper(watir_object)
  type = element.type if watir_object.tag_name.to_sym == :input
  cls = ::PageObject::Elements.element_class_for(watir_object.tag_name, type)
  cls.new(watir_object.to_subtype)
end

Notice that we are retrieving the type of the base element rather than the watir_object.

@jkotests jkotests added the bug label Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant