I am using the watir-webdriver ruby gem. It starts the browser (Chrome) and begins to load a page. The page is loading too slowly, and watir-webdriver raises a timeout error. Ho
You can stop Google loading the page using AutoIT to send the Escape key. This is similar to what you originally tried to do, but using AutoIT directly rather than through the broken Watir::Browser object.
require 'watir-webdriver'
require 'win32ole'
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 5
@browser = Watir::Browser.new :chrome, :http_client => client
begin
@browser.goto "http://www.nst.com.my/"
rescue
autoit = WIN32OLE.new("AutoItX3.Control")
autoit.AutoItSetOption("WinTitleMatchMode", 2)
autoit.WinActivate("Google")
autoit.Send("{ESC}")
end
@browser.goto "http://www.google.ca"
Note: I tried to get autoit.ControlSend("Google", "", "", "{ESC}")
to work so that it would not need the browser to be the active window. While it worked when run by itself, for some reason I could never get it to work in the above script (ie key was sent but browser did not react as expected).