2014-09-27 86 views
0

我想單擊循環的基礎上的按鈕。Selenium :: WebDriver :: Error :: ElementNotVisibleError當循環點擊使用Watir按鈕

讓我們說我有下面的代碼

if ind == 2 
    export_id = @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").id 
    @browser.div(:id => export_id).click 
else 
    @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").click 
end 

但它顯示了錯誤的指標值「2」,錯誤的是

Selenium::WebDriver::Error::ElementNotVisibleError: 
Element is not currently visible and so may not be interacted with 

誰能幫助我在這種情況下?

+1

例外說元素不可見這會工作。您可能需要執行一些其他操作才能看到它 - 例如將鼠標懸停在下拉菜單上。沒有看到頁面,很難告訴你確切的問題。 – 2014-09-27 13:14:52

+0

在許多情況下,在單擊元素之前嘗試諸如sleep 2之類的東西竟然可以工作。嘗試告訴Ruby在嘗試點擊它之前等待一兩秒鐘。 – daremkd 2014-09-27 13:35:53

+0

@daremkd我嘗試了睡眠和wait_until_present,但它仍然失敗,它獲得的ID與錯誤的一樣 – Sai 2014-09-29 10:54:25

回答

1

如果您提供了正確的html,那將會很棒。

嘗試此一次,你

if ind == 2 
    export_id = @browser.div(:id => export_id) 
    export_id.click 
else 
    @browser.div(:id => pop_id).div(:class => /actionDropDownItem groupChild nonSelectable/,:title => "Export").click 
end