2013-05-15 58 views
1

我正在測試登錄頁面。在某些時候(間歇性地讀取)加載主頁需要無限的時間。在這種情況下,下面的命令無法完成 -Webdriver - 無限頁面加載提交

driver.findElement(By.id("Login")).submit(); 

我知道隱式&明確等待的。 這些等待只爲findElement或DOM相關的行動,但不服從命令((參考文獻都適用:https://sqa.stackexchange.com/questions/2606/what-is-seleniums-default-timeout-for-page-loading

調試日誌跟蹤 -

15 May 2013 16:42:08 DEBUG wire:77 - << "{"name":"submitElement","sessionId":"949f6c8f-a8fc-4e13-b4da-bf6c19c893fe","status":0,"value":""}" 
15 May 2013 16:42:08 DEBUG DefaultClientConnection:152 - Connection shut down 
15 May 2013 16:42:08 DEBUG ThreadSafeClientConnManager:272 - Released connection is not reusable. 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:434 - Releasing connection [HttpRoute[{}->http://127.0.0.1:7055]][null] 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:679 - Notifying no-one, there are no waiting threads 
15 May 2013 16:42:08 DEBUG SalesForce:153 - Verify next page 
15 May 2013 16:42:08 DEBUG ThreadSafeClientConnManager:221 - Get connection: HttpRoute[{}->http://127.0.0.1:7055], timeout = 120000 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:350 - [HttpRoute[{}->http://127.0.0.1:7055]] total kept alive: 0, total issued: 0, total allocated: 0 out of 2000 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:523 - No free connections [HttpRoute[{}->http://127.0.0.1:7055]][null] 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:369 - Available capacity: 2000 out of 2000 [HttpRoute[{}->http://127.0.0.1:7055]][null] 
15 May 2013 16:42:08 DEBUG ConnPoolByRoute:549 - Creating new connection [HttpRoute[{}->http://127.0.0.1:7055]] 
15 May 2013 16:42:08 DEBUG DefaultClientConnectionOperator:145 - Connecting to 127.0.0.1:7055 
15 May 2013 16:42:08 DEBUG RequestAddCookies:132 - CookieSpec selected: best-match 
15 May 2013 16:42:08 DEBUG RequestAuthCache:75 - Auth cache not set in the context 
15 May 2013 16:42:08 DEBUG DefaultHttpClient:643 - Attempt 1 to execute request 
15 May 2013 16:42:08 DEBUG DefaultClientConnection:264 - Sending request: GET /hub/session/949f6c8f-a8fc-4e13-b4da-bf6c19c893fe/title HTTP/1.1 
15 May 2013 16:42:08 DEBUG wire:63 - >> "GET /hub/session/949f6c8f-a8fc-4e13-b4da-bf6c19c893fe/title HTTP/1.1[\r][\n]" 
15 May 2013 16:42:08 DEBUG wire:63 - >> "Accept: application/json, image/png[\r][\n]" 
15 May 2013 16:42:08 DEBUG wire:63 - >> "Cache-Control: no-cache[\r][\n]" 
15 May 2013 16:42:08 DEBUG wire:63 - >> "Host: 127.0.0.1:7055[\r][\n]" 
15 May 2013 16:42:08 DEBUG wire:63 - >> "Connection: Keep-Alive[\r][\n]" 
15 May 2013 16:42:08 DEBUG wire:63 - >> "[\r][\n]" 
15 May 2013 16:42:08 DEBUG headers:268 - >> GET /hub/session/949f6c8f-a8fc-4e13-b4da-bf6c19c893fe/title HTTP/1.1 
15 May 2013 16:42:08 DEBUG headers:271 - >> Accept: application/json, image/png 
15 May 2013 16:42:08 DEBUG headers:271 - >> Cache-Control: no-cache 
15 May 2013 16:42:08 DEBUG headers:271 - >> Host: 127.0.0.1:7055 
15 May 2013 16:42:08 DEBUG headers:271 - >> Connection: Keep-Alive 

基本上DefaultClientConnection沒有收到200 OK &的命令只是掛起

尋找解決方案關閉瀏覽器以防瀏覽器沒有響應提交命令等待之後g一段特定的時間。

+0

你的意思是像driver.close()? –

+0

什麼。我只想在特定的等待之後進入下一個陳述情況 – praneel

回答

0

我猜ID「登錄」是一種形式。

您可以改爲選擇表單的提交按鈕(假設存在)並在按鈕上調用.click(),而不是在窗體上調用.submit()?

然後你應該可以使用隱式或顯式等待。

編輯:

提交表格後,您可以進行自定義的方法來等待響應,並超時,如果必要的話後,要關閉瀏覽器。

 int tryCount = 0; 
     boolean desiredResponseReceived = false; 
     while (desiredResponseReceived == false && tryCount < 20) { 
      String statusText = (String) js.executeScript("return xhr.statusText;"); 
      if (statusText.indexOf("200") != -1) { 
       desiredResponseReceived = true; 
      } 
      else { 
       Thread.sleep(250); 
       tryCount++; 
      } 
     } 

     if (desiredResponseReceived == false) { 
      driver.quit(); 
     } 

正如所寫的,如果在5秒內沒有在xhr響應中出現「200」,該方法將關閉瀏覽器。 (因爲它每隔250毫秒檢查20次,最終在達到if (desiredResponseReceived == false)之前檢查並關閉瀏覽器)。

+0

是的,聽起來像是一個很好的建議。讓我試試&更新 – praneel

+0

嘗試點擊選項。與click()或submit()相同的結果。沒有改變n的行爲 – praneel

+0

我編輯了我的答案,在響應中等待「200」,然後超時。 –