单击Watir中的js按钮后如何处理新的浏览器弹出? [英] How to handle new browser pop up after clicking a js button in Watir?

查看:85
本文介绍了单击Watir中的js按钮后如何处理新的浏览器弹出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ruby中使用watir,我可以打开浏览器,
以用户名/密码形式输入一些值,但随后按Enter,然后单击提交按钮(实际上是按回车,它很容易编码),它将为我们的应用程序弹出一个新的浏览器窗口,然后我发现我无法控制新的浏览器。我该怎么办?

I am trying to using watir in ruby, I am able open a browser, enter some values to a username/password form, but then I press enter, then I click the submit button (actually it is pressing an enter, it is easiler to code), it would pop up a new browser windows for our application, then I found I have no control to the new browser. What can I do?

除了我的问题外,新的浏览器窗口没有菜单栏,工具栏,导航栏,因此我无法打开IE开发者工具栏在新浏览器中找到网页中元素的名称。

In addition to my problem, the new browser window got no menubar, no toolbar, no navigation bar, thus I cannot open the IE developer toolbar to find the name of the element in the webpage in the new browser.

顺便说一句,我的应用只能支持IE。

By the way, my app can only support IE.

我尝试了attach方法,但它确实起作用:

I tried the attach method, but it does work:

C:/ Ruby187 / lib / ruby /gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb:302:

C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb:302:

在attach_browser_window中:无法找到窗口标题为(?-mix:New浏览器标题)(Watir :: Exception :: NoMatchingWindowFoundException)

in `attach_browser_window': Unable to locate a window with title of (?-mix:New browser title) (Watir::Exception::NoMatchingWindowFoundException)

    from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb

:150:在`_attach_init'

:150:in `_attach_init'

    from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb

:144:in从test1.rb:36附上

:144:in `attach' from test1.rb:36

解决方案

附加方法能够处理新窗口。
http://rdoc.info/gems/watir/1.8 .1 / Watir / IE.attach

Attach method is able to handle new window. http://rdoc.info/gems/watir/1.8.1/Watir/IE.attach

例如


browser = Watir::Browser.new
browser.text_field(:id,'username').set 'username')
browser.button(:index,1).click
# popped up the new window
popup = Watir::Browser.attach(:title,'Foobar')

仅使用弹出的窗口,您可以改写浏览器变量。

If you will use only the popped up window, you can overwrite browser variable instead.

这篇关于单击Watir中的js按钮后如何处理新的浏览器弹出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆