Skip to content

Instantly share code, notes, and snippets.

@corona6
Created May 28, 2019 05:05
Show Gist options
  • Save corona6/b5408a5c0f0955047f27655135066a4d to your computer and use it in GitHub Desktop.
Save corona6/b5408a5c0f0955047f27655135066a4d to your computer and use it in GitHub Desktop.
use headless_chrome
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