almost 6 years ago
Here, we discuss that how to capture a screenshot in Selenium WebDriver.
Scenario to be automated:
WebDriver Code goes as below:
import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class CaptureScreenshot { public static void main(String[] args) throws IOException, InterruptedException { WebDriver driver = new FirefoxDriver(); driver.get("http://google.com"); driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS); driver.manage().window().maximize(); WebElement textField = driver.findElement(By.xpath(".//*[@id='sb_ifc0']")); textField.click(); textField.sendKeys("testing"); driver.findElement(By.xpath(".//*[@id='sblsbb']/button")).click(); Thread.sleep(3000); File image = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(image, new File("D:\\screenshot_1.png")); } }
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)