Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdriver Screenshot

When taking a screenshot using Selenium Webdriver on windows with python, the screenshot is saved directly to the path of the program, is there a way to save the .png file to a specific directory?

like image 591
user1152578 Avatar asked Jan 17 '12 18:01

user1152578


People also ask

Can we take screenshot in Selenium Webdriver?

In order to capture a screenshot in Selenium, one has to utilize the method TakesScreenshot. This notifies WebDrive that it should take a screenshot in Selenium and store it. In the above snippet, OutputType defines the output type for the required screenshot.

How do you take multiple screenshots in Selenium?

There are multiple ways to do this. Create one separate class file as ScreenCapture and inside this class file create two methods. One method is for when your particular testcase is run successfully and another method is for when your testcase is failed during execution of your test scripts.

How do you take a screenshot in Java?

Taking a Screenshot Using RobotThe dimensions of the screen are accessible through the Toolkit class by using its getScreenSize() method. On systems with multiple screens, the primary display is used by default. After capturing the screen into BufferedImage, we can write it to the file with ImageIO. write().


1 Answers

Use driver.save_screenshot('/path/to/file') or driver.get_screenshot_as_file('/path/to/file'):

import selenium.webdriver as webdriver import contextlib  @contextlib.contextmanager def quitting(thing):     yield thing     thing.quit()  with quitting(webdriver.Firefox()) as driver:     driver.implicitly_wait(10)     driver.get('http://www.google.com')     driver.get_screenshot_as_file('/tmp/google.png')      # driver.save_screenshot('/tmp/google.png') 
like image 182
unutbu Avatar answered Oct 28 '22 16:10

unutbu