QA *_*eks 2 watir watir-webdriver
下面是我试图自动化的网页html,当我使用Watir时,它正确地找到了元素但没有使用watir-webdriver.
<td width="87">
<input type="image" style="height: 34px; width: 83px; border-width: 0px;" src="/test/test/img/Order-Online-Form_18.gif" id="order1_Next1" name="$Next1">
</td>
Run Code Online (Sandbox Code Playgroud)
我使用以下代码:
require 'rubygems'
require 'watir'
browser = watir::Browser.new
browser.goto 'test.com'
test = @browser.td(:xpath,"//input[@id='order1_Next1']").exists?
puts test
Run Code Online (Sandbox Code Playgroud)
当我使用watir时,它返回true但如果我使用watir-webdriver,则返回false.你能帮我解释为什么watir-webdriver不能识别xpath
谢谢
当你正在寻找一个"按钮"时,你正试图找到一个'td'.
并且使用XPath选择器几乎肯定是找到此元素的错误方法.
使用具有id属性的button元素类型会更好:
require 'watir-webdriver'
b = Watir::Browser.start 'http://dl.dropbox.com/u/18859962/qageeks.html'
b.button(:id => 'order1_Next1').exists? # => true
b.button(:xpath,"//input[@id='order1_Next1']").exists? # => true
Run Code Online (Sandbox Code Playgroud)
如果你坚持使用xpath,你可以使用最后一行,但是你可以看到它更冗长,更不清楚.
| 归档时间: |
|
| 查看次数: |
2350 次 |
| 最近记录: |