【问题标题】:How to use --screenshot in headless firefox in Selenium with python如何在 Selenium 的无头 Firefox 中使用 --screenshot 和 python
【发布时间】:2018-06-23 01:07:50
【问题描述】:

使用@DebanjanB 在How to make firefox headless programatically in Selenium with python? 中的回复, 我正在尝试使用他的代码并将其更改为使用 --screenshot 参数,但它不起作用。 这是我的代码

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()

有人可以告诉我如何在 Python 和 Firefox 中使用 --screenshot 吗?谢谢

【问题讨论】:

    标签: selenium screenshot headless


    【解决方案1】:

    没关系,我找到了办法。有一个函数 driver.save_screenshot('test.png')。我保留了我的问题并将其注释掉。

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-26
      • 2019-06-22
      • 2018-06-27
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 2018-06-15
      相关资源
      最近更新 更多