Replace implicit wait with explicit wait (selenium webdriver & java)

前端 未结 5 1296
轮回少年
轮回少年 2020-11-22 12:37

How can I replace this implicit wait with an explicit one?

driver = new ChromeDriver(capabilities);

driver.manage().deleteAllCookies();

5条回答
  •  感情败类
    2020-11-22 13:17

    Using implicit and Explicit waits.

    Though we weigh Explicit wait to be more advisable, you should check for the scenario you are catering for.

    For example in your code, you are calling the wait just to get the time for the delete call to complete. Which can be improved without using any wait at all.

     Set cookies = driver.manage().getCookies();
     for(;cookies.size() != 0;){
       driver.manage().deleteAllCookies();
     }
    

    **You can use While loop i suppose **

    Having said that, to use explicit wait. I have used it for taking actions on the pop up, that I get during the app testing.

    WebDriverWait wait = new WebDriverWait(appDriver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    appDriver.switchTo().alert().dismiss();
    

    So use no wait if you can verify the condition of execution, and use explicit wait when you know what to wait for. Hope this helps a bit.

提交回复
热议问题