WebDriver :: Error :: UnknownError:Session没有驱动程序。浏览器窗口可能已关闭 - 无法识别确认覆盖

时间:2012-03-11 15:11:44

标签: selenium selenium-webdriver webdriver watir watir-webdriver

我正在尝试自动化从电子商务应用程序中的产品页面进行的购买。用户点击“立即购买”按钮后,会弹出一个登录用户输入用户凭据。用户成功登录后,将显示确认覆盖(并且弹出窗口中的登录将关闭),并带有确认购买选项。但是,webdriver无法识别父浏览器窗口上的会话。

以下是我用来驱动测试的脚本:

require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.start "http://qa02.barnesandnoble.com/w/james-pattersons-witch-   and-wizard-james-patterson/1101936910?ean=2940000962145&itm=1&usri=james+patterson"
browser.button(:caption,'Buy Now').click
sleep 5 #Wait until the Log in Pop comes up
puts browser.windows.size
browser.window(:url,/signin/).use
browser.text_field(:id, "login-email").set "flite-test3@book.com"
browser.text_field(:id, "login-password").set "bookcom"
browser.button(:caption,/Secure Sign In/).click
sleep 8 #Wait until confirm overlay appears
puts browser.windows.size
browser.window(:url,/w/).use
browser.button(:caption,/Confirm/).click




?> browser.button(:caption,/Confirm/).click
Selenium::WebDriver::Error::UnknownError: Session [a758cfba-7f00-f148-b9e6-f969c9402228] has no driver. The browser window may have been closed.
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/command_processor.js:10583:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/driver_component.js:9631:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/driver_component.js:9785:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/driver_component.js:9732:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/driver_component.js:10781:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:1935:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:2261:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:1168:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:1616:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:1464:in `unknown'
    from [remote server] file:///var/folders/wM/wMhMTIyBE9Cdrfjt6sgbPk+++TQ/-Tmp-/webdriver-profile20120311-1255-16gc4a5/extensions/fxdriver@googlecode.com/components/httpd.js:1333:in `unknown'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:594:in `raw_execute'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:572:in `execute'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:183:in `switchToDefaultContent'
    from /Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/target_locator.rb:68:in `default_content'
    from /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.5.3/lib/watir-webdriver/browser.rb:166:in `assert_exists'
    from /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.5.3/lib/watir-webdriver/elements/button.rb:52:in `locate'
    from /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.5.3/lib/watir-webdriver/elements/element.rb:361:in `assert_exists'
    from /Library/Ruby/Gems/1.8/gems/watir-webdriver-0.5.3/lib/watir-webdriver/elements/element.rb:94:in `click'
    from secondruby.rb:15>> 

1 个答案:

答案 0 :(得分:2)

我不完全理解browser.window.use的技术细节,因为这是我第一次看到它。但是,我能够通过这样做来运行脚本:

require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.start "http://www.barnesandnoble.com/w/private-games-james-patterson/1104155019?ean=9780316206822&itm=1&usri=james+patterson"
browser.button(:caption,'Buy Now').click
sleep 5 #Wait until the Log in Pop comes up
puts browser.windows.size
browser.window(:url,/signin/).use do
    browser.text_field(:id, "login-email").set "flite-test3@book.com"
    browser.text_field(:id, "login-password").set "bookcom"
    browser.button(:caption,/Secure Sign In/).click
end
sleep 8 #Wait until confirm overlay appears
puts browser.windows.size
browser.window(:url,/w/).use
browser.button(:caption,/Confirm/).click

我所做的改变是:

  1. 弹出操作作为一个块传递给browser.window.use
  2. 第二个browser.window.use不再需要,所以被删除了
  3. 网址已更改为“http://www.barnesandnoble.com/w/private-games-james-patterson/1104155019?ean=9780316206822&itm=1&usri=james+patterson”,因为我无法获取工作的原始网址。我认为这是无关紧要的。