I suspect it is a timing issue, since it is taking the 2nd window a while
to load, and watir won't recognize it until it is done.
Try:
agent.window(index: 1).when_present.use



On Thu, Jan 22, 2015 at 11:36 AM, Greg Allen <[email protected]>
wrote:

> 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)
> agent.goto 'http://www.google.com'
>
> 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!
>
>  --
> --
> Before posting, please read http://watir.com/support. In short: search
> before you ask, be nice.
>
> [email protected]
> http://groups.google.com/group/watir-general
> [email protected]
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Watir General" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to