Reputation: 355
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
Upvotes: 10
Views: 7682
Reputation: 355
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()
Upvotes: 13