Radio buttons (with uppercase 'type' in the HTML) in Watir Firefox Webdriver
I开发者_如何转开发 use Firefox 4 with Watir Webdriver. I have a web page with the following:
<input id="RadioM" type="RADIO" value="M" name="Field_SEX">Male
<input id="RadioF" type="RADIO" value="F" name="Field_SEX">Female
These really seem standard radio buttons to me. My Watir code:
browser.radio( :id , "RadioM" ).set
The error message is:
C:/Program Files/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.1/lib/watir-webdriver/elements/element.rb:241:in `ass
ert_exists': unable to locate element, using {:id=>"RadioM", :tag_name=>"input", :type=>"radio"} (Watir::Exception::Unknown
ObjectException)
from C:/Program Files/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.1/lib/watir-webdriver/elements/radio.rb:
9:in `set'
from I:/watir/one.rb:22:in `<main>'
What happens?
Looks like you've found a bug in watir-webdriver - it won't find the input element if the 'type' attribute is upper cased (which is indeed valid HTML).
As a workaround, you can do this:
browser.element(:id, "RadioM").to_subtype.set
Container#element returns a generic element (in this case avoiding the input type check which is failing for the upper cased attribute), which you can "cast" to a more specific element with Element#to_subtype (which returns a Watir::Radio).
精彩评论