I am utilizing the watir-webdriver gem in Ruby for browser automation. When I initiate Chrome, the web page starts to load, but it often takes too long, leading to a timeout error from watir-webdriver. What methods can I employ to stop the browser from continuing to load the page?
require 'watir-webdriver'
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 10
@browser = Watir::Browser.new :chrome, http_client: client
urls = [
'http://google.com/',
'http://yahoo.com/',
'http://www.veryslowwebsite.com/', # This site loads slowly
'http://drupal.org/',
'http://www.msn.com/',
'http://stackoverflow.com/'
]
urls.each do |link|
begin
@browser.goto(link)
puts "Loaded successfully: #{link}"
rescue
puts "Loading timed out: #{link}"
end
end
It appears that while the browser is loading a page, it does not process other commands. Is there a way to cancel the current loading process and proceed with the next command?
UPDATE
I’ve discovered a capability flag called loadAsync
. I wonder if this could potentially help in addressing my issue? I’m uncertain on how to configure watir to utilize this when initiating chromedriver.