cheezy/page-object

UnknownObjectException when checking existence of an adjacent element that does not exist

jkotests opened this issue · 0 comments

An UnknownObjectException occurs when:

  • Checking the existence (or presence) of an adjacent element (eg followig_sibling, preceding_sibling, etc) and
  • The element does not exist.

For example, given the following page, where the div does not have a following sibling:

<html>
  <body>
    <div id="abc">a</div>
  </body>
</html>

An exception occurs when checking if a following sibling exists:

class MyPage
	include PageObject

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

page = MyPage.new(browser)
page.abc_element.following_sibling.present?
#=> C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:798:in `rescue in element_call': timed out after 2 seconds, waiting for #<Watir::HTMLElement: located: false; {:id=>"abc", :tag_name=>"div"} --> {:adjacent=>:following, :index=>0}> to be located (Watir::Exception::UnknownObjectException)
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:815:in `element_call'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:791:in `rescue in element_call'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:815:in `element_call'
#=> 	from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.16.5/lib/watir/elements/element.rb:123:in `tag_name'
#=> 	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:97:in `following_sibling'