抑制Watir中的自动关闭窗口 [英] Suppress auto-closing window in Watir
问题描述
我正在使用Watir和Chromedriver来自动在某些网站上提交表单.我必须登录并提交多个表格.问题是,当我单击提交"按钮时,页面会自动关闭,因此当我转到('next_url')时,会出现此错误:
I am using Watir with Chromedriver to automate form submission on some website. I have to login and submit multiple forms. The problem is, when I click the submit button the page the page automatically closes, so when I goto('next_url') I get this error:
/Users/jackz/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/remote/response.rb:52:在'assert_ok'中: "auto_id"不指向打开的标签页(Selenium :: WebDriver :: Error :: UnknownError)
/Users/jackz/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': 'auto_id' does not refer to an open tab (Selenium::WebDriver::Error::UnknownError)
Watir实例仍然存在,但是窗口已关闭.我可以每次创建一个新实例,但是每次都必须再次登录,这将花费更长的时间.
The Watir instance is still there, but the window is closed. I could create a new instance every time, but then I would have to login again every time and this would take longer.
那我该怎么办:
在同一Watir实例中打开一个新窗口
Open a new window in the same Watir instance
或
禁止我提交后关闭窗口
require 'watir-webdriver'
@b = Watir::Browser.new :chrome
@b.goto(URL)
@b.buttons.first.click
#this is when the window closes
@b.goto(NEW_URL)
#then I get an error
谢谢
推荐答案
我想出了我自己问题的答案.我可以使用javascript在Watir中打开一个新窗口:
I figured out an answer to my own question. I can open a new window in Watir using javascript:
b = Watir::Browser.new
b.execute_script("window.open()")
b.windows.last.use
这将打开一个窗口,我可以在其中填写表格,然后当该窗口自动关闭时,我仍然可以使用原始窗口.可能不是最好的解决方案,但目前可以使用.
This opens a window where I can fill out the form, then when the window automatically closes I still have the original window to work with. Probably not the best solution, but it works for now.
这篇关于抑制Watir中的自动关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!