Created
May 28, 2019 05:05
-
-
Save corona6/b5408a5c0f0955047f27655135066a4d to your computer and use it in GitHub Desktop.
use headless_chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara' | |
require 'selenium-webdriver' | |
Capybara.register_driver :chrome do |app| | |
Capybara::Selenium::Driver.new(app, browser: :chrome) | |
end | |
Capybara.register_driver :headless_chrome do |app| | |
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( | |
chromeOptions: { args: %w[headless disable-gpu] } | |
) | |
Capybara::Selenium::Driver.new( | |
app, | |
browser: :chrome, | |
desired_capabilities: capabilities | |
) | |
end | |
Capybara.javascript_driver = :headless_chrome | |
session = Capybara::Session.new(:headless_chrome) | |
url = "https://instant.io/" | |
session.visit(url) | |
session.attach_file('upload', '4_Pieces.html') | |
sleep 5 | |
puts session.all('a')[1][:href] | |
puts Process.pid | |
Process.daemon | |
puts Process.pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment