How do I use Selenium Webdriver on headless Chrome?

后端 未结 3 1040
滥情空心
滥情空心 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:19

    I've written a blog post about how to do it. Summing up:

    1) Make sure you have Chrome version 57+ on Linux, 59+ on macOS or 60+ on Windows;

    2) Add/update the gem selenium-webdriver;

    3) Make sure you’re using ChromeDriver version 2.30 or higher;

    4) Add the following driver to your spec_helper.rb or rails_helper.rb:

    Capybara.register_driver :chrome do |app|
      Capybara::Selenium::Driver.new app, browser: :chrome,
        options: Selenium::WebDriver::Chrome::Options.new(args: %w[headless disable-gpu])
    end
    
    Capybara.javascript_driver = :chrome
    

提交回复
热议问题