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 6, 2018 in Selenium by Martin
• 4,320 points
3,067 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 6, 2018 by nsv999
• 5,500 points

Related Questions In Selenium

0 votes
1 answer
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,320 points
2,311 views
0 votes
1 answer
0 votes
2 answers

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,500 points
8,157 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
7,242 views
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,890 points
4,985 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
6,203 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 28, 2018 in Selenium by nsv999
• 5,500 points
23,597 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP