Selenium Explicit Wait
Selenium Explicit Wait
Selenium Explicit Wait is a type of wait in Selenium WebDriver used to pause the execution until a specific condition is met or the maximum specified time has elapsed.
Unlike implicit wait (which applies globally) and Thread.sleep() (which halts unconditionally), explicit wait is applied to a particular element or condition. Explicit wait is mostly used when we need to Wait for a specific content/attribute change after performing any action, like when application gives AJAX call to system and get dynamic data and render on UI.
We need to define a wait statement for certain condition to be satisfied until the specified timeout period. If the Webdriver finds the element within the timeout period the code will get executed.
Explicit Wait Example
/<span class="hljs-variable">*Explicit</span> <span class="hljs-keyword">wait</span> <span class="hljs-keyword">for</span> <span class="hljs-keyword">state</span> dropdown field<span class="hljs-variable">*/</span>
WebDriverWait <span class="hljs-keyword">wait</span> = new WebDriverWait(driver, 3<span class="hljs-number">0</span>);
<span class="hljs-keyword">wait</span>.<span class="hljs-keyword">until</span>(ExpectedConditions.visibilityOfElementLocated(
By.id(<span class="hljs-string">"statedropdown"</span>)));
In this example, Webdriver waits up to 30 seconds before throwing Exception (TimeoutException – Timed out after 30 seconds waiting for visibility of element) or if it finds the element, it will return in 0 – 30 seconds.
Selenium Tutorials
Selenium Tutorials on this website: