Using @DebanjanB's reply in How to make firefox headless programatically in Selenium with python?, I'm trying to use his code and change it to use --screenshot argument, but it's not working. This is my code
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument( "--screenshot test.jpg http://google.com/" )
driver = webdriver.Firefox( firefox_options=options )
driver.get('http://google.com/')
print driver.title
driver.quit()
sys.exit()
Can someone let me know please how to use --screenshot with Python and Firefox? Thanks
Selenium offers a lot of features and one of the important and useful feature is of taking a screenshot. In order to take a screenshot of webpage save_screenshot() method is used. save_screenshot method allows user to save the webpage as a png file.
Firefox in headless mode, can be run once we configure the geckodriver path. We shall then use the FirefoxOptions class, and send the headless knowledge to the browser with setHeadless method and pass true as a parameter to it.
Screenshots are beneficial, specifically in headless test execution, where you cannot see the GUI of the application. Still, Selenium will capture it by a screenshot and store it in a file so that you can verify the application later.
Headless Execution Firefox Driver It is quite simple to run your tests in the headless mode. You need simply to add the "--headless" argument to the FirefoxOptions object. * However, the current official version of Mozilla Firefox is 56.
Nevermind, I found a way. there is a function driver.save_screenshot('test.png'). I kept the line from my question and commented it out.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import sys
options = Options()
options.add_argument( "--headless" )
# options.add_argument( "--screenshot test.jpg http://google.com/" )
driver = webdriver.Firefox( firefox_options=options )
driver.get('http://google.com/')
driver.save_screenshot('test.png')
print driver.title
print driver.current_url
driver.quit()
sys.exit()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With