Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am using:

driver.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);

But it still fails continuously for the below element

driver.findElement(By.id("name")).clear();

 driver.findElement(By.id("name")).sendKeys("Create_title_01");

I have added wait code:

 for (int second = 0;; second++) {

        if (second >= 120) fail("timeout");

        try { if (isElementPresent(By.id("name"))) break; } catch (Exception e) {}

        Thread.sleep(1000);

    } 

Shouldn't implicit wait take care of waiting till an element is found? Also would it be better if I use Explicit wait instead of the code I have added that has Thread.sleep()?

1 Answer

0 votes
by (62.9k points)

Implicit wait:

The implicit wait will tell to the web driver to wait for a certain amount of time before it throws a "No Such Element Exception". The default setting is 0. Once we set the time, the web driver will wait for that time before throwing an exception.

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

The explicit wait is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or the maximum time exceeded before throwing an "ElementNotVisibleException" exception.
 

Explicit wait :

The explicit wait is an intelligent kind of wait, but it can be applied only for specified elements. The explicit wait gives better options than that of an implicit wait as it will wait for dynamically loaded Ajax elements.

Once we declare explicit wait we have to use "ExpectedCondtions" or we can configure how frequently we want to check the condition using Fluent Wait. These days while implementing we are using Thread.Sleep() generally it is not recommended to use

WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut);

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!

Browse Categories

...