How to decrease the wait time for NoSuchElementException in Selenium?
I think you're looking for setting the implitic wait time for your driver:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
For simple cases thats ok to use, for more advanced automation, I'd change it to an explicit wait (using WebDriverWait
).
More on waits:http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Use WebDriverWait
to decrease waiting time ex (wait 5 seconds):
(new WebDriverWait(driver, 5)).until(ExpectedConditions.visibilityOf(name));
We can use explicit wait for this scenario but have to be careful with the expected conditions being used.
WebDriverWait wait=new WebDriverWait(driver,10);wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
Sometimes visibilityOf(Name) will not work since mostly finding of webelement name needs the findElement statement to be used.
WebElement name=driver.findElement(Locator);
This step may fail if element is not present!