简体   繁体   中英

In Selenium do I need to disable an implicit wait when using an explicit wait?

I have set my implicit wait to 10 secs when my driver is created. When I wish to use explicit wait, do I have to set implicit wait to 0?

Here is a sample:

WebDriver webDriver = new FirefoxDriver();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Now I want to use Explicit wait

Do I have to do webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); or it is not necessary?

WebDriverWait wait = new WebDriverWait(webDriver, WAIT_FOR_TIMEOUT_SEC);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id)));

It's not necessary to re-declare implicit wait time back to zero.

Reason: When you say that you want to use an explicit wait, it only means that your implicit wait time isn't enough to wait for the element to appear and so you declare an explicit wait after a particular action.

When Should you use an Implicit wait: Implicit wait is a way to tell selenium to wait for a particular period of time after executing each and every action. This helps in synchronisation of most actions that you perform. The longer time you give the slower your test executes. More about implicit wait

When Should you use an Explicit wait: Explicit wait is used when a particular action takes time to perform or load on to the DOM. This does not tell selenium to wait for a particular time after each and every action but instead tells selenium to wait for a period of time before executing a particular action only. More about explicit wait

WARNING from Selenium Website: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10s and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM