Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Fix exists? which was incorrectly returning true in some cases
Browse files Browse the repository at this point in the history
We have a bug in the way elements are located. Given the following page:
<html>
  <body>
    <div id="foo">
      <div id="bar">
      </div>
    </div>
  </body>
</html>

And the following test cases:
1. Browser.div(:id, 'foo').exists? => true
2. Browser.div(:id, 'bar').exists? => true
3. Browser.div(:id, 'foo').div(:id, 'bar').exists? => true
4. Browser.div(:id, 'bar').div(:id, 'foo').exists? => false
5. Browser.div(:id, 'something').div(:id, 'else').exists? => true
6. Browser.div(:id, 'foo').div(:id, 'hello').exists? => false

Case 5 incorrectly returns true. This diff fixes this bug.

Note:
there might be a more elegant way of fixing things, but I'm not super familiar with the jssh syntax. Feel
free to suggest a better fix.
  • Loading branch information
Alok Menghrajani committed Dec 7, 2010
1 parent ef32065 commit b56664d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions firewatir/lib/firewatir/element.rb
Expand Up @@ -281,6 +281,13 @@ def locate_tagged_element(tag, how, what, types = nil, value = nil)
#puts "container name is: " + @container.element_name
#locate if defined? locate
#@container.locate

# We cannot assume that the container exists at this point, because code like:
# b.div(:id, "something_that_does_not_exist").h2(:text, /foobar/).exists? would return true
if (!@container.exists?)
return nil
end

jssh_command << "var elements_#{@@current_level}_#{tag} = #{@container.element_name}.getElementsByTagName(\"#{tag}\");"
if(types != nil and (types.include?("textarea") or types.include?("button") ) )
jssh_command << "elements_#{@@current_level}_#{tag} = #{@container.element_name}.getElementsByTagName(\"*\");"
Expand Down

0 comments on commit b56664d

Please sign in to comment.