2013-10-31 112 views
0

這裏有什麼問題?我想等待下一個任務,直到我的頁面完全加載。 問題:沒有錯誤,但司機不等待:-(Selenium WebDriver:等待document.readyState

# wait for page load 
wait2 = Selenium::WebDriver::Wait.new(:timeout => 20) # seconds 
count = 0 
begin 
    raise("maximum attempt crossed #{count} times") if count > 3 
    wait2.until { 
    self.getDriver.execute_script("return document.readyState;") == "complete" 
    } 
rescue Timeout::Error 
    count +=1 
    retry 
end 

#do sth 
+0

您是否遇到任何錯誤?如果是這樣的錯誤是什麼...如果沒有錯,您的意思是? –

+0

錯誤:超時! – fabian

回答

0

我會處理如下問題:

wait = Selenium::WebDriver::Wait.new(:timeout => 20) # seconds 
count = 0 
begin 
    raise("maximum attempt crossed #{count} times") if count > 3 
    # if the page having title 'page_title' is not loaded within 20 seconds 
    # time out error will be thrown,which will be handled by the rescue clause. 
    wait.until { driver.title == 'page_title' } 
rescue Timeout::Error 
    count +=1 
    retry 
end 
+0

我實際上現在不在新頁面上的page_title或其他任何東西。 接着就,隨即? – fabian

+0

@fabian我以此爲例。但異常塊是主要技巧..你可以嘗試這種技術.. –

+0

我已經更新了我的初始代碼塊。 No:沒有錯誤,但腳本沒有等待足夠長的時間...我總是得到一個空白頁 – fabian

0

這似乎是爲我工作

相關問題