in select.rb, this is the method for select_by_string:
<pre><code>def select_by_string(how, string)
xpath = option_xpath_for(how, string)
if multiple?
elements = @element.find_elements(:xpath, xpath)
no_value_found(string) if elements.empty?
elements.each { |e| e.click unless e.selected? }
elements.first.text
else
begin
e = @element.find_element(:xpath, xpath)
rescue Selenium::WebDriver::Error::NoSuchElementError
no_value_found(string)
end
e.click unless e.selected?
safe_text(e)
end
end</code></pre>
After selecting the element option, it calls safe_text(e):
<pre><code>def safe_text(element)
element.text
rescue Selenium::WebDriver::Error::ObsoleteElementError,
Selenium::WebDriver::Error::UnhandledAlertError
# guard for scenario where selecting the element changes the page, making
our element obsolete
''
end</code></pre>
It looks like there are two exceptions that you rescue to protect against this
step erroring when selecting something causes a page to load, but in my testing
I've come across a third error that is not being rescued and thus causing false
failures for selecting elements (successfully selects it, page loads, then it
fails because it can't call safe_text successfully).
The rescue in safe_text needs Selenium::WebDriver::Error::JavascriptError added
in to prevent against this happening. So the code should be:
<pre><code>def safe_text(element)
element.text
rescue Selenium::WebDriver::Error::ObsoleteElementError,
Selenium::WebDriver::Error::UnhandledAlertError,
Selenium::WebDriver::Error::JavascriptError
# guard for scenario where selecting the element changes the page, making
our element obsolete
''
end</code></pre>
---
Reply to this email directly or view it on GitHub:
https://github.com/watir/watir-webdriver/issues/185
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development