How can I make WebDriver wait for few seconds?

0 votes

I'm working on Selenium-WebDriver with Java & I added the below statement:

driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
WebElement textbox = driver.findElement(By.id("textbox"));

This is because the page takes a few seconds to load the UI. That's why I gave a 2 seconds implicitwait. But I always get an error saying unable to locate the element textbox. And then when I added

Thread.sleep(2000);

Everythng works fine. So what's wrong?

Apr 5, 2018 in Selenium by Martin
• 4,220 points
256 views

1 answer to this question.

0 votes

Well, just try increasing the amount of time for implicitwait(). Even though Thread.sleep() works with 2s wait, something more than that should definately work for implicitwait(). Imlicitly wait for 10s and if the element is found within that time, then you won't have any problem. 

But besides, there are 2 types of waits: Explicit wait and Implicit wait. Explicit wait works like this:

WebDriverWait.until(WebElement("textbox").isVisible());

But, Implicit wait works like this:

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

So, there is no funny reason any of this might not work. Try it out once.

answered Apr 5, 2018 by nsv999
• 5,050 points

Related Questions In Selenium

0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,220 points
342 views
0 votes
1 answer
0 votes
1 answer

How to pause for few seconds in Selenium?

you can locate an element that loads ...READ MORE

answered Jul 6, 2018 in Selenium by Meci Matt
• 9,400 points
443 views
+4 votes
1 answer

How can I configure Eclipse for using Selenium?

Follow the following steps to configure your ...READ MORE

answered Dec 12, 2018 in Selenium by Nabarupa
174 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
248 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
621 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
240 views
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
4,999 views