b.select_list(:id, "MainContent_drpVehicleType").when_present.options.each do |option|
option.select
b.select_list(:id, "MainContent_drpMake").when_present.options.each do |option|
option.select
b.select_list(:id, "MainContent_drpModel").when_present.options.each do |option|
option.select
b.button(:id,"MainContent_imgbtnsearch").click
end
end
end
我有三个下拉列表取决于以前的值我必须逐个选择每个选项,然后单击按钮。 * 虽然这样做会导致以下错误 *元素不再附加到DOM(Selenium :: WebDriver :: Error :: StaleElementReferenceError)
还试过:
b.driver.manage.timeouts.implicit_wait = 3
答案 0 :(得分:0)
尝试以下方法,
b.select_list(:id, "MainContent_drpVehicleType").when_present.options.each do |type_option|
type_option.select
sleep 5
b.select_list(:id, "MainContent_drpMake").when_present.options.each do |make_option|
make_option.select
sleep 5
b.select_list(:id, "MainContent_drpModel").when_present.options.each do |model_option|
model_option.select
sleep 5
b.button(:id,"MainContent_imgbtnsearch").click
end
end
end
答案 1 :(得分:0)
假设每个选项都是唯一的,您可以尝试:
以下实现了这个想法(虽然它没有经过测试,因为我没有类似的页面来测试):
b.select_list(:id, "MainContent_drpVehicleType").when_present.options.each do |option|
#Select a vehicle type and wait for the last make option to no longer appear
last_make_option = b.select_list(:id, "MainContent_drpMake").when_present.options.last
option.select
last_make_option.wait_while_present
b.select_list(:id, "MainContent_drpMake").when_present.options.each do |option|
#Select a make and wait for the last model option to no longer appear
last_model_option = b.select_list(:id, "MainContent_drpModel").when_present.options.last
option.select
last_model_option.wait_while_present
b.select_list(:id, "MainContent_drpModel").when_present.options.each do |option|
option.select
b.button(:id,"MainContent_imgbtnsearch").click
end
end
end
请注意:
答案 2 :(得分:0)
我有一个问题是点击后会发生什么?如果页面刷新或执行某些操作,那么您可以使用上面的嵌套方法干杯,因为在第一次单击之后,没有办法在第三个列表上更改您的选择并再次单击..
如果上述方法都不起作用,您可能需要进行一些窥探,以便在列表中做出选择时查看正在发生的HTML请求(可能是REST API)。您可以使用它来构建自己的多维数组来映射选择。或者您可以使用类似于上面的循环结构来获取各种选择列表内容,然后循环并执行您的点击
获得地图后,使用类似于上面的嵌套循环按维度迭代维度,但是在最里面的循环中执行所有操作,这相当于此伪代码
gather the types and store
for each stored-type do
pick the type
gather makes available for that type and store
for each make of that type do
pick the type, then make
gather models available for that type
for each model of that make do
goto starting point
select type
select make
select model
click
validate what should happen
end
end
end