【发布时间】:2014-02-14 01:11:55
【问题描述】:
这样尝试是不可能的吗?我添加了代码来扩展允许自定义选择器的能力:
module Watir
class ElementLocator
alias :old_normalize_selector :normalize_selector
def normalize_selector(how, what)
case how
when :data_sku
[how, what]
else
old_normalize_selector(how, what)
end
end
end
end
这是我试图从随机数组中选择它的代码。即使中间两行未注释,我仍然会收到错误。
$monthlydata = ["GC311Z-02","GC307Z-02","GC308Z-02","GC309Z-02","GC310Z-02"].sample
#Watir::Wait.until { @b.radio(:data_sku, $monthlydata) }
#@b.radio(:xpath, "//input[@data_sku='$monthlydata']").exists?
@b.radio(:xpath, "//input[@data_sku='$monthlydata']").set **(line causing the error)**
我得到的错误是 UnknownObjectException:无法定位元素。引发错误的行是显示的最后一行。
更新
我更新的代码出现超时错误:
if @b.url == "http://www.website.com/cart/plans?ProductId=product"
$monthlydata = ["GC311Z-02","GC307Z-02","GC308Z-02","GC309Z-02","GC310A-02"].sample
assert @b.radio(:data_sku, $monthlydata).when_present.set
end
$monthlymin = ["GC504Z","GC505Z","GC506Z","GC507Z","GC508Z"].sample
assert @b.radio(:data_sku, $monthlymin).when_present.set
$monthlytxt = ["GC313Z-02","GC314Z-02","GC315Z-02","GC316Z-02","GC320Z-02"].sample
assert @b.radio(:data_sku, $monthlytxt).when_present.set
堆栈跟踪:
Error: test_goproject(TestShoppingCart)
Watir::Wait::TimeoutError: timed out after 30 seconds, waiting for {:data_sku=
>"GC309Z-02", :tag_name=>"input", :type=>"radio"} to become present
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.7/lib/watir-webdriver/wa
it.rb:33:in `until'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.7/lib/watir-webdriver/wa
it.rb:106:in `method_missing'
C:/Users/User.Name/Downloads/shoppingcart2.rb:95:in `test_goproject'
92:
93: if @b.url == "http://www.website.com/cart/plans?ProductId=product"
94: $monthlydata = ["GC311Z-02","GC307Z-02","GC308Z-
02","GC309Z-02","GC310Z-02"].sZmple
=> 95: assert @b.radio(:data_sku, $monthlydZtZ).when_pr
esent.set
96: end
97:
98: $monthlymin = ["GC504Z","GC505Z","GC506Z","GC507Z","GC50
8Z"].sample
【问题讨论】:
-
谢谢,我从 $monthlydata 中检查了我的数组后发现了这一点。我抓取 $monthlydata 值的区域并不在我抓取的所有网页中。
-
要在上面添加我的堆栈跟踪,因为我仍然在尝试定位无线电元素时遇到超时。
-
问题已解决。没关系。
标签: ruby watir watir-webdriver custom-attribute