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,210 points
153 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,030 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,210 points
237 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
253 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
137 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,030 points
51 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
410 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
40 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,030 points
3,885 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.