2015-01-21 40 views
1

在隱式等待的情況下,如果WebDriver沒有立即找到元素,它會等待指定的時間,並且如果在指定的時間過後未找到元素,則會拋出異常。顯式等待的條件被檢查多少次?

意味着在隱式等待的情況下,WebDriver會檢查元素兩次(最大)。 1)立即2)(如果立即未找到)在指定時間結束時。

但在明確等待的情況下,檢查條件的頻率如何?

我的意思是如果它檢查條件成爲真/不空或只有兩次像隱式等待條件每秒?

+1

WebDriverWait默認調用ExpectedCondition每500毫秒,直到它成功返回。 – 2015-01-21 11:58:07

+1

謝謝幫助手! – TDHM 2015-01-21 12:22:49

+0

你是歡迎.. – 2015-01-21 12:24:39

回答

2

默認情況下,它會檢查每500毫秒(即輪詢)。 所以從源代碼你可以看到 -

public final static long DEFAULT_SLEEP_TIMEOUT = 500;

public WebDriverWait(WebDriver driver, long timeOutInSeconds) { 
    this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, DEFAULT_SLEEP_TIMEOUT); 
} 

它在內部調用 -

protected WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, 
     long sleepTimeOut) { 
    super(driver, clock, sleeper); 
    withTimeout(timeOutInSeconds, TimeUnit.SECONDS); 
    pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS); 
    ignoring(NotFoundException.class); 
    } 
+1

謝謝,Vivek!最重要的是要放入代碼。 – TDHM 2015-01-21 12:24:32

+0

樂於幫助哥們......歡呼聲...... – 2015-01-21 12:32:06