2017-06-02 132 views
0

正確的等待,等待一個元素消失?正確等待等待元素消失?

我有它加載一個按鈕後,例如點擊一個ajax裝載機,是我的方法正確序等待一個特定的負載棒,這需要屏幕的整個寬度和高度上消失?

public void waitUntilAjaxLoaderDisapears() { 
    // Wait up to 2minutes for the element to disappear 
    WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60); 
    ajaxWait.pollingEvery(100, TimeUnit.SECONDS); 
    try { 
     //tempWait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".modal-body"))); 
     ajaxWait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(@class, 'ajax_loader')]"))); 
    } catch (UnhandledAlertException e) { 
     Alert alert = driver.switchTo().alert(); 
     alert.accept(); 
    }catch (NoAlertPresentException e) { 
     // 
    }catch (StaleElementReferenceException e) { 
     // do nothing 
    } catch (NullPointerException e) { 
     // do nothing 
    } catch (Exception e) { 
     // do nothing 
    } 
} 
+0

「屏幕上消失」,我們才能創造這個消失的屏幕webelement?當裝載器屏幕出現我可以證實該定位器是上述 –

+0

@santhosh庫馬爾是輪詢時間應小於實際等待時間。它必須小於60 – Gbru

+2

一個觀測所列 –

回答

1

我想我得到了問題。輪詢時間應該少於整個等待時間。因此,它可以是,

WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60); 
ajaxWait.pollingEvery(**5**, TimeUnit.SECONDS); 

而不是

WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60); 
ajaxWait.pollingEvery(100, TimeUnit.SECONDS); 

希望這有助於你。謝謝。