How to pause for few seconds in Selenium

0 votes

I want to wait for something to load and then take it's screenshot and save it.

Below is the code:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.abc.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
    File scr = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scr,new File("/Desktop/image.png"));
} catch (Exception e) { 
       e.printStackTrace(); 
}
driver.close();

The page is not waiting for me, is there any method to get the driver/page to wait for few seconds?

Jul 6, 2018 in Selenium by Johnathon
• 9,090 points
6,999 views

1 answer to this question.

0 votes

you can locate an element that loads after the initial page loads and then makes Selenium wait till it finds that element, as shown below:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id")));
answered Jul 6, 2018 by Meci Matt
• 9,460 points

Related Questions In Selenium

0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 29, 2018 in Selenium by bug_seeker
• 15,520 points
1,676 views
+2 votes
1 answer
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
12,617 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
8,572 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,910 points
6,629 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
7,519 views
0 votes
1 answer

How to use Enter/Return Key in Selenium

You can use the below code: import org.openqa.selenium.Keys WebEle ...READ MORE

answered Apr 18, 2018 in Selenium by Meci Matt
• 9,460 points
2,622 views
+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
193,879 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP