2013-04-01 101 views
1
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(硒:: webdriver的::錯誤:: StaleElementReferenceError)逐個選擇選項使用watir-webdriver-

也試過:

b.driver.manage.timeouts.implicit_wait = 3 
+1

的問題是可能的Watir試圖訪問選項的下拉菜單已刷新之前。您需要一種方法來確定下拉菜單何時完成刷新 - 可能會檢查下拉列表的值是否已更改(注意,如果每組選項都是唯一的,這將會起作用)。 –

+0

感謝您的回覆..但我有超過100個選項的價值,它是不可能設置每個值..有任何方法可用來確定等待,直到選項刷新... –

+0

「make」的列表是唯一的對於每個「車型」?同樣,每個「製造」都有哪些「模型」是唯一的? –

回答

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 
+0

雖然這可能起作用,但考慮到有100多個選項正在測試中,這可能會很慢。 –

+0

感謝您的回覆..仍然發生相同的錯誤 –

+0

什麼時候發生錯誤,在什麼步驟? –

0

假設每個選項都是uni闕,你可以嘗試:

  1. 獲得的最後一個選項在從屬列表
  2. 進行選擇在當前列表
  3. 等待在步驟1中不再選項出現

以下實現這個想法(儘管它沒有經過測試,因爲我沒有類似的頁面來測試):

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 

請注意:

  • 該代碼假定從屬列表的最後一個選項將始終更改。如果不是這樣,您可能需要檢查相關列表的所有選項。
+0

謝謝回覆...讓同error..Let我解釋我的問題顯然 1)在Vechile類型有三種選擇AUTO,HD,海洋 2)如果我選擇了Vechile型汽車是指與TAT Vechile使需要在下拉菜單中加載 3)選擇模型選項後,(它只包含所有品牌的一個值)。 4)後達單擊搜索按鈕 5)現在會顯示如下所有的值來搜索 6相關)我要檢查每一個選項,並點擊搜索按鈕,需要顯示所有值相關搜索 –

+0

如果你硬編碼一個特定的例子(即,而不是遍歷所有選項),是否有任何錯誤?如果不是的話,那麼我猜猜查克恰恰在那裏讓人耳目一新。訪問重現該問題的頁面或html會非常有幫助。 –

+0

是查克是正確的......點擊按鈕後,它是刷新..並遺憾不能提供訪問達頁.. –

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 
+0

感謝您提供您的寶貴時間..頁面不刷新..並沒有驗證任何其他..只是我需要顯示與特定下拉列表(Vechile類型,品牌,型號)相關的信息..任何想法 –

+0

對不起頁面刷新..你是正確的.. –

+0

一旦刷新,所有這些對象集合幾乎得到無效。而不是使用動態集合,您可能需要獲取列表的內容,提取到您自己的集合(也許是多維數組),然後使用存儲的循環內的值,使選擇 –