How can I make Selenium wait for an element before screenshot?

What method can I use in Selenium to wait for a certain element to appear before taking a screenshot?

The code that i am trying is :

The code I already have is

WebDriver driver = new FirefoxDriver();


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

try {

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/home/Desktop/image.png"));

} catch (Exception e) {




is there another method that I can use to get the driver/page to wait for X amount of seconds?

Hi Anusha

If you want to delay a certain number of seconds, rather than to respond as soon as possible, here is a function for pause similar to what Selenium IDE offers:

public void pause(Integer milliseconds){ try { TimeUnit.MILLISECONDS.sleep(milliseconds); } catch (InterruptedException e) { e.printStackTrace(); } }

You can follow this source to get better insights : Selenium Pause in Java (WebDriver) | FRET