How do I use Selenium Webdriver on headless Chrome?

后端 未结 3 956
滥情空心
滥情空心 2021-02-20 15:51

I\'m learning to use Selenium for basic things like taking a screenshot, scraping, and testing and would like to use it with headless Chrome, which is now stable as of Chrome 59

3条回答
  •  走了就别回头了
    2021-02-20 16:18

    I found this blog post useful for setting up headless chrome with selenium in ruby

    require "selenium-webdriver"
    
    # configure the driver to run in headless mode
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--headless')
    driver = Selenium::WebDriver.for :chrome, options: options
    
    driver.navigate.to "https://www.google.com"
    
    # resize the window and take a screenshot
    driver.manage.window.resize_to(800, 800)
    driver.save_screenshot "screenshot.png"
    

提交回复
热议问题