I am using the following code to right-click on a link and open the target in a new tab in FireFox.
profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:native_events => false)
driver = Selenium::WebDriver.for(:firefox, profile: profile, desired_capabilities: caps)
agent = Watir::Browser.new(driver)
link = agent.a(:class => 'gb_ib')
agent.driver.action.context_click(link.wd).send_keys(:arrow_down).send_keys(:return).perform
puts agent.windows.count
puts agent.windows.last.title
agent.windows.last.use
It works fine, except that Watir does not seem to recognize the newly opened tab. The new tab gets opened, and I would expect the "agent.window.last.use" command to change the focus to that new tab. However, it does not.
In fact, printing out the number of windows results in 1 and the title of that page is "Google".
How can I make Watir recognize that I have opened a new tab in this manner?
Thanks!