据我所知,使用 :value 作为识别按钮元素的一种方式应该可以正常工作。甚至有多个示例,例如在watirwebdriver.com网站上显示了这一点。但是,当我尝试它时,我得到一个相当标准的无法找到消息
这是标识按钮的页面中 HTML 的一部分
<div class="data-form-holder row-fluid">
<h4>I am:</h4>
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn fb-user-type" name="fbRadios" value="is_agent">An Agent</button>
<button type="button" class="btn fb-user-type" name="fbRadios" value="is_grower">A Grower</button>
</div>
</div>
这是尝试与按钮交互时发生的情况(在这种情况下通过 IRB 进行故障排除)
1.9.3p125 :006 > b.buttons(:class => "fb-user-type").count
=> 2 # yep, I can find the buttons I want, so not a frame issue etc.
1.9.3p125 :008 > b.button(:class => "fb-user-type").value
=> "is_agent" # I can even get the value of the first one, which is as expected./
1.9.3p125 :009 > b.button(:value => "is_agent").flash
Watir::Exception::UnknownObjectException: unable to locate element, using {:value=>"is_agent", :tag_name=>"button"}
from /Users/cvanderlinden/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:490:in `assert_exists'
from /Users/cvanderlinden/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:420:in `style'
from /Users/cvanderlinden/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.6.4/lib/watir-webdriver/elements/element.rb:232:in `flash'
from (irb):9
from /Users/cvanderlinden/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
#well that was annoying, I used a value I know exists, it just read it to me, but
# I cannot find the button that way?
1.9.3p125 :004 > b.buttons(:value => "is_agent").count
=> 0 # kinda expected since flash on a single button failed..
1.9.3p125 :018 > b.button(:text => "An Agent").flash #this works
=> #<Watir::Button:0x7d6f5d1340a3b6b8 located=true selector={:text=>"An Agent", :tag_name=>"button"}>
1.9.3p125 :020 > b.button(:text => "An Agent").value
=> "is_agent" #also shows me the value I expect
1.9.3p125 :022 > b.button(:text => "An Agent").attribute_value("value")
=> "is_agent" #same answer via another means
1.9.3p125 :023 > b.button(:value => "is_agent").exists?
=> false #and yet, finding it by value, supported but failing..
任何人都知道为什么我不能通过价值来识别?