1

Here is my selenium web driver initialization for firefox browser.

driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

Even though I gave implicit wait selenium not waiting for the element. It is throwing the not found exception immediately. If I put Thread.sleep then it is working fine without any issues. But putting Thread.sleep everywhere the test case contains now more Thread.sleep than the actual test case code. Can anyone suggest me the right way to do this?

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
Rajeshkumar
  • 815
  • 12
  • 35
  • Why are you not using `ExplicitWait` instead using `WebDriverWait`?? – Saurabh Gaur Aug 30 '16 at 12:26
  • although the preferred way is via explicit waits but above should work without any issue, are you able to replicate this issue on public url? – Mrunal Gosar Aug 30 '16 at 12:35
  • @MrunalGosar I tried the same without sleep in the public url. working fine. In my local it is throwing error – Rajeshkumar Aug 30 '16 at 13:21
  • @MrunalGosar Even in the login page the button is getting clicked quickly but the action is not happening. If i put sleep for 5 sec, before click it is working fine. It is dojo.button – Rajeshkumar Aug 30 '16 at 13:22
  • would u be able to put up a github project with sample application replicating your issue..else there is no other way of finding what is going wrong in your case – Mrunal Gosar Aug 30 '16 at 14:25

1 Answers1

1

in that case you should use ExplicitWait to wait for an specific element to be visible or present, because it's not a good practice tosleep the thread. I'll recommend to use:

WebDriver driver wait = new WebDriverWait(driver, "time here");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath)));
Jose Bernhardt
  • 887
  • 1
  • 10
  • 24