0

Does the first line alone make webdriver wait for 10 seconds? or do I need to have both?

 WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));

I'm confused about what statement makes driver wait?Is this statement enough?

WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
ERJAN
  • 23,696
  • 23
  • 72
  • 146

2 Answers2

1
WebDriverWait wait = new WebDriverWait(firefoxDriver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

You can add more to the ignore list by calling ignoring(exceptions to add) method.

Santoshsarma
  • 5,627
  • 1
  • 24
  • 39
1

There are three distinct wait mechanisms Selenium provides so far I know. Explicit,Implicit and Fluent. See this. The one you have mentioned is Explicit. Explicit wait is meant to wait for element to meet certain condition you tell the WebDriver. Such as element's visibility(the one you are using),element exists etc. There is a class in org.openqa.selenium.support.ui named ExpectedConditions that has good number of members to provide different mechanism for waiting for the element.See here for a complete list.

Going back to your question: WebDriverWait wait = new WebDriverWait(firefoxDriver,10); only defines the wait and the length WebDriver should wait to meet condition provided by you(in second line.) The actual wait happens wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathID)));. WebDriver tries to find the element matching the xpathID and it's visibilty on the page and after 10s it throws exception. If WebDriver finds the target element before 10s it will not wait 10s and move forward.

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73