2016-01-20 88 views
1

我有以下元素:硒等元素出現,dissapear

<div class="ui-helper-hidden" id="shell.indicator.busy"> 
    <label>Processing...</label> 
    <br /> 
    <img src="/RightCrowd/Images/loading.gif" alt="" /> 
</div> 

,它似乎是這樣的:

Processing

我想等待它出現,然後消失並繼續訪問元素。這出現在Web應用程序的大多數頁面上。我們嘗試了一些東西,但有時可以看到硒,有時不是,雖然我可以用我的眼睛看到它。

我相信這個處理圖像出現在當前頁面的頂部,並且使用當前處理程序可能沒用。不確定。

我們試過這樣的事情:

 WebElement element = (new WebDriverWait(webDriver, 10)) 
        .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[contains(@src,'/Images/loading.gif')]"))); 

     boolean processingEnd = (new WebDriverWait(webDriver, timeoutWaitForProgressbar)) 
        .until(ExpectedConditions.invisibilityOfElementLocated(By.id("shell.indicator.busy"))); 

所以我們都試過XPath和ID ...請讓我知道什麼是處理這種情況的最好辦法。

+0

當您使用xpath和ID嘗試它時發生了什麼?它是否拋出異常?哪個例外? –

+0

這是一個TimeoutException。代碼嘗試捕獲,但我沒有複製粘貼所有內容。我有興趣在它出現時正確檢測,並檢測它何時消失。 –

+0

等待它出現或等待其消失的超時時間?如果你遇到超時,它最終會發現它嗎? –

回答

3

默認情況下,WebDriverWait將每隔半秒檢查一次預期狀態狀態。我會嘗試更頻繁地使用FluentWait類發出預期的狀態檢查請求:

Wait wait = new FluentWait(driver) 
    .withTimeout(timeoutWaitForProgressbar, SECONDS) 
    .pollingEvery(100, MILLISECONDS); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("shell.indicator.busy"))); 
+0

作爲評論,pollingEvery不接受double值,但我可以使用毫秒。還是行不通。我會等待別人回覆... –

+0

現在比較穩定。我使用xpath(例如By.xpath(「// img [contains(@src,'/ Images/loading.gif')]」))而不是id,現在看起來更一致。 –

+0

fluentwait頁面無法正常工作 –