watir/watir-webdriver — pull request #275 by titusfortner (2014-10-03 23:14:49+00:00)
Title: Rescues Frame Exception in element locate

I've spent all day trying to recreate this for a spec. If the element itself goes stale, the tests throw a StaleElementReferenceError (like it should). I have no idea how in my test the element isn't stale, but comes back as the element not being a frame, when you can see from the debug info I included that getElementTagName returns an iframe right before it tries to switch to it.

I'm also not sure this rescue is the right way to handle this, or if there is a bug somewhere deeper in the code, but this lets my test pass when I do a when_present call.

Stack Trace:
expected no Exception, got # with backtrace:
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/iframe.rb:167:in `rescue in switch!'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/iframe.rb:165:in `switch!'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/iframe.rb:157:in `method_missing'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:89:in `find_first_by_multiple'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:34:in `locate'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/element.rb:567:in `locate'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/element.rb:544:in `assert_exists'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/element.rb:44:in `exists?'
# /home/titus/workspace/watir-webdriver/lib/watir-webdriver/elements/element.rb:431:in `present?'

This is the debug info I'm pulling from Selenium::WebDriver::Remote::Bridge#execute
Commands: *args
Returned: raw_execute(*args)['value']

Commands: [:findElement, {}, {:using=>"id", :value=>"menuFrame"}]
Returned: {"ELEMENT"=>"0.6930554306600243-1"}
Commands: [:getElementTagName, {:id=>"0.6930554306600243-1"}]
Returned: iframe
Commands: [:getElementTagName, {:id=>"0.6930554306600243-1"}]
Returned: iframe
Commands: [:isElementDisplayed, {:id=>"0.6930554306600243-1"}]
Returned: true
Commands: [:switchToFrame, {}, {:id=>nil}]
Returned:
Commands: [:findElement, {}, {:using=>"id", :value=>"menuFrame"}]
Returned: {"ELEMENT"=>"0.6930554306600243-1"}
Commands: [:getElementTagName, {:id=>"0.6930554306600243-1"}]
Returned: iframe
Commands: [:getElementTagName, {:id=>"0.6930554306600243-1"}]
Returned: iframe
Commands: [:switchToFrame, {}, {:id=>#}]