watir webdriver - 找不到窗口 [英] watir webdriver - window not found
问题描述
另一个问题.此代码在 add_task
...
Another watir issue. This code works until add_task
...
登录后,验证窗口关闭并返回带有登录密钥的主窗口.但我收到此错误:
After login, the auth window closes and goes back to main window with login key. But I get this error:
你好
测试 add_task
testing add_task
[远程服务器] file:///var/folders/3w/b7rcpqfj7kl3wtv56jt99yx00000gn/T/webdriver-profile20120919-9069-1ua1lm9/extensions/fxdriver@googlecode.com/components/command_2unknown12:command_processor.js:: 没有找到窗口.浏览器窗口可能已关闭.(Selenium::WebDriver::Error::NoSuchWindowError)
[remote server] file:///var/folders/3w/b7rcpqfj7kl3wtv56jt99yx00000gn/T/webdriver-profile20120919-9069-1ua1lm9/extensions/fxdriver@googlecode.com/components/command_processor.js:10212:in `unknown': Window not found. The browser window may have been closed. (Selenium::WebDriver::Error::NoSuchWindowError)
require 'rubygems'
require 'test/unit'
require 'watir-webdriver'
class Login
def basic_auth(logintype,usr,pwd)
$browser.goto("http://change.com")
$browser.link(:class,'joinchange').wait_until_present
join_link = $browser.link(:class,'joinchange')
join_link.click
$browser.window(:title, 'Sign In').wait_until_present
$browser.window(:title, 'Sign In').use
if logintype == 'fb'
$browser.link(:name, 'login-facebook id=').click
$browser.text_field(:id,'email').set(usr)
$browser.text_field(:id,'pass').set(pwd)
puts 'form submit'
sleep 3
$browser.form(:id,'login_form').submit
puts 'hello world'
else
$browser.text_field(:id,'lgnId').set('changes')
$browser.text_field(:id,'pwdId').set('letmeinnow')
sleep 3
$browser.form(:name,'LoginActionForm').submit
puts 'hi there'
end
end
def add_task
puts "testing add_task"
$browser.link(:class,'nextStep').click
end
end
$browser = Watir::Browser.new
login = Login.new
login.basic_auth('test','usr','pwd')
sleep 3
login.add_task
推荐答案
我认为问题是切换到登录弹出窗口后,脚本没有切换出来.因此,在 add_task 期间,当它尝试单击链接时,它正在尝试登录已关闭的弹出窗口.
I believe that the problem is that after switching to the Sign In popup window, the script does not switch out of it. So during add_task when it tries to click the link, it is trying in the Sign In popup, which is closed.
在 basic_auth
方法中,您希望将要在弹出窗口中执行的操作作为块传递给 window.use
方法.
In the basic_auth
method, you want to pass the actions you want performed in the popup as a block to the window.use
method.
所以你想要:
$browser.window(:title, 'Sign In').use do
if logintype == 'fb'
$browser.link(:name, 'login-facebook id=').click
$browser.text_field(:id,'email').set(usr)
$browser.text_field(:id,'pass').set(pwd)
puts 'form submit'
sleep 3
$browser.form(:id,'login_form').submit
puts 'hello world'
else
$browser.text_field(:id,'lgnId').set('changes')
$browser.text_field(:id,'pwdId').set('letmeinnow')
sleep 3
$browser.form(:name,'LoginActionForm').submit
puts 'hi there'
end
end
(注意第一行末尾添加的 do
和末尾额外的 end
.)
(Notice the do
added at the end of the first line and the extra end
at the end.)
这篇关于watir webdriver - 找不到窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!