page-object
page-object copied to clipboard
Undefined method 'type' when the retrieved adjacent elements includes inputs
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'
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
.