Ruby 完成测试后,Watir Webdriver不会在Firefox中显示对话框

Ruby 完成测试后,Watir Webdriver不会在Firefox中显示对话框,ruby,firefox,webdriver,watir,watir-webdriver,Ruby,Firefox,Webdriver,Watir,Watir Webdriver,我正在将webdriver与FF38一起使用,但在脚本完成后将浏览器窗口保持打开状态。如果我在测试后继续,我发现对话框不再在该窗口中打开 该脚本旨在自动化表单输入,而不是手动输入,但该网站确实使用对话框来表示选择(例如,删除脚本刚刚输入的数据,以便我可以在不覆盖信息的情况下重新运行脚本) 有没有办法在我完成后断开webdriver对话框处理 我觉得自己有点傻,但我的搜索还没有结果,所以考虑到我对ruby和webdriver的新认识,我可能在搜索中使用了错误的词 例如: require "wati

我正在将webdriver与FF38一起使用,但在脚本完成后将浏览器窗口保持打开状态。如果我在测试后继续,我发现对话框不再在该窗口中打开

该脚本旨在自动化表单输入,而不是手动输入,但该网站确实使用对话框来表示选择(例如,删除脚本刚刚输入的数据,以便我可以在不覆盖信息的情况下重新运行脚本)

有没有办法在我完成后断开webdriver对话框处理

我觉得自己有点傻,但我的搜索还没有结果,所以考虑到我对ruby和webdriver的新认识,我可能在搜索中使用了错误的词

例如:

require "watir-webdriver"

l_Browser = Watir::Browser.new :firefox
l_Browser.goto "http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert"

# Click the button that opens the dialog
l_Browser.div(:class => "container").div(:class => "iframecontainer"). \
    div(:class => "iframewrapper").iframe(:id => "iframeResult"). \
    button(:onclick => "myFunction()").click
结果是将出现一个弹出窗口,但不会出现弹出窗口。脚本完成后,如果尝试单击按钮,则不会出现弹出窗口

这包括即使在脚本期间没有触发弹出窗口(即:,最后一行被注释掉)。。。脚本运行完成后,watir webdriver打开的窗口中不会出现弹出窗口。(如果我在脚本运行时单击按钮,它们将打开,但在脚本运行后不会打开)

根据以下答案,我使用:

begin
    b = Watir::Browser.new :firefox
    File.open('d:\\MARK.TXT', 'w') {|f| f.write(YAML.dump(b)) }
    # Load MessageBox and wait here
    b = YAML.load(File.read('d:\\MARK.TXT'))
ensure
    if !b.nil?
        b.close()
    end
end
。。。但它目前允许忽略错误。。。我只是不知道从长远来看忽视它们是多么明智:

    D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/windows/handle.rb:50:in `exit_code': The handle is invalid. (6) (ChildProcess::Error)
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/windows/process.rb:41:in `exited?'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/abstract_process.rb:147:in `poll_for_exit'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/binary.rb:59:in `quit'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/launcher.rb:62:in `quit'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/bridge.rb:75:in `quit'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/driver.rb:165:in `quit'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.7.0/lib/watir-webdriver/browser.rb:136:in `close'
        from D:/Users/risendevil/Documents/Aptana Studio 3 Workspace/Ruby Test/Default.rb:19:in `<main>'
D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/windows/handle.rb:50:“退出代码”中的句柄无效。(6) (ChildProcess::错误)
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/windows/process.rb:41:在“退出”中
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/childprocess-0.5.6/lib/childprocess/abstract\u process.rb:147:in'poll\u for_exit'
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/binary.rb:59:in'quit'
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/launcher.rb:62:in'quit'
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/firefox/bridge.rb:75:in'quit'
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/driver.rb:165:在'quit'中
from D:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.7.0/lib/watir-webdriver/browser.rb:136:在“关闭”中
来自D:/Users/risendevil/Documents/aptanastudio3workspace/Ruby-Test/Default.rb:19:in`'
版本: 火狐38.0.5 硒(0.2.11) selenium webdriver(2.46.2、2.45.0)
watir webdriver(0.7.0)

我在回答你的问题时学到了一些新东西:

重要的是

my_object=SomeObject.new
my_object.some_method#=>返回您期望的结果
File.open('path/to/some.File','w'){| f | f.write(YAML.dump(my_object))}
#你想干什么就干什么
my_object_reload=YAML.load(File.read('path/to/some.File'))
my_object_reload.some_method#=>返回您期望的结果
您甚至可以直接在浏览器上执行此操作:

b=Watir::Browser.new
b、 后藤http://google.com“#=>转到谷歌
File.open('path/to/some.File','w'){| f | f.write(YAML.dump(b))}
b=零
#想干什么就干什么,想等多久就等多久。
#(免责声明:“只要您愿意”,可能存在主要限制。)
b=YAML.load(File.read('path/to/some.File'))
b、 后藤http://yahoo.com“#=>去雅虎

在回答你的问题时,我学到了一些新的东西:

重要的是

my_object=SomeObject.new
my_object.some_method#=>返回您期望的结果
File.open('path/to/some.File','w'){| f | f.write(YAML.dump(my_object))}
#你想干什么就干什么
my_object_reload=YAML.load(File.read('path/to/some.File'))
my_object_reload.some_method#=>返回您期望的结果
您甚至可以直接在浏览器上执行此操作:

b=Watir::Browser.new
b、 后藤http://google.com“#=>转到谷歌
File.open('path/to/some.File','w'){| f | f.write(YAML.dump(b))}
b=零
#想干什么就干什么,想等多久就等多久。
#(免责声明:“只要您愿意”,可能存在主要限制。)
b=YAML.load(File.read('path/to/some.File'))
b、 后藤http://yahoo.com“#=>去雅虎

您能否从脚本的作用(代码片段的帮助)和期望的结果等方面重申这个问题?具体来说,您可以描述为什么在执行脚本后需要保留浏览器以及您希望下一步做什么?我尝试复制我认为您在这里尝试做的事情,但我可以得到我想要的JS对话,我不包括browser.close,因为我对警报没有问题,只要脚本正在运行,但是,一旦脚本停止运行,我希望浏览器窗口保持打开状态。我相信我已经正确回答了这个问题——请参见下面的答案。您可以从脚本的作用(代码片段的帮助)以及您期望的结果方面重述这个问题吗?具体来说,您可以描述为什么在执行脚本后需要保留浏览器以及您希望下一步做什么?我尝试复制我认为您在这里尝试做的事情,但我可以得到我想要的JS对话,我不包括browser.close,因为我对警报没有问题,只要脚本正在运行,但是一旦脚本停止运行,我希望浏览器窗口保持打开状态。我相信我已经正确地回答了这个问题——请看下面我的答案。考虑到这些工具,我觉得这些工具非常有用。我没有睡觉,而是使用messagebox来更好地控制关闭对象。作为一个合理的警告,即使浏览器成功关闭,仍然会出现不可避免的错误。@MarkSchultz您能详细说明错误吗?我相信这是存储对象以供以后访问的规范方法,因此如果您遇到Watir或som错误
require "watir-webdriver"

l_Browser = Watir::Browser.new :firefox
l_Browser.goto "http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert"

l_Browser.iframe(:id => 'iframeResult').button(:xpath => "//button[text()='Try it']").when_present.click # click on "Try it" button
l_Browser.alert.close # closing popup