Watir Firefox Webdriver 中的单选按钮(在 HTML 中使用大写“类型”)
我使用 Firefox 4 和 Watir Webdriver。 我有一个网页,其中包含以下内容:
<input id="RadioM" type="RADIO" value="M" name="Field_SEX">Male
<input id="RadioF" type="RADIO" value="F" name="Field_SEX">Female
这些对我来说确实看起来是标准的单选按钮。 我的 Watir 代码:
browser.radio( :id , "RadioM" ).set
错误消息是:
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>'
会发生什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您在 watir-webdriver 中发现了一个错误 - 如果“type”属性是大写的(这确实是有效的 HTML),它将找不到输入元素。
作为解决方法,您可以这样做:
Container#element 返回一个通用元素(在这种情况下,避免了大写属性失败的输入类型检查),您可以使用 Element#to_subtype 将其“转换”为更具体的元素(返回一个 Watir::Radio)。
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:
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).