1

另一个女仆问题。此代码有效,直到add_task...

登录后,身份验证窗口关闭并使用登录密钥返回主窗口。但我得到这个错误:

你好呀

测试 add_task

[远程服务器] file:///var/folders/3w/b7rcpqfj7kl3wtv56jt99yx00000gn/T/webdriver-profile20120919-9069-1ua1lm9/extensions/fxdriver@googlecode.com/components/command_processor.js:10212:in `unknown': 窗口不是成立。浏览器窗口可能已关闭。(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
4

1 回答 1

1

我相信问题在于切换到登录弹出窗口后,脚本并没有切换出来。因此,在 add_task 尝试单击链接时,它会尝试关闭已关闭的登录弹出窗口。

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.

So you want:

$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

(Notice the do added at the end of the first line and the extra end at the end.)

于 2012-09-19T21:48:07.360 回答