使用watir在ruby程序完成后,Chrome浏览器会自动关闭 [英] chrome browser closes automatically after the program finishes in ruby using watir

查看:463
本文介绍了使用watir在ruby程序完成后,Chrome浏览器会自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用chrome 56,chrome驱动程序2.27(最新版本)和selenium web driver 3.1.0。提及问题( https://github.com/seleniumhq / selenium-google-code-issue-archive / issues / 1811 )一旦程序结束,chrome会关闭所有的实例,并且它不会给我一个调试的机会。我只是想知道这是否被修复,为什么它仍然在发生?或者我错过了什么?
我正在使用下面的代码。任何帮助表示赞赏。

I am using chrome 56, chrome driver 2.27(latest release) with selenium web driver 3.1.0. Referring to the issue(https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1811) where chrome closes all the instances once the program finishes and it does not give me a chance to debug. I just want to know if this is fixed then why it is still happening ? or i am missing something ? I am using the following code. Any help is appreciated.

require "uri"
require "net/http"
require 'watir-webdriver'
require 'selenium-webdriver'

@b = Watir::Browser.new :chrome
@b.goto 'http://www.google.com'

推荐答案

首先,不推荐使用watir-webdriver gem。更新的代码在watir gem中。此外,您不需要直接要求任何其他宝石。

Firstly, watir-webdriver gem is deprecated. The updated code is in the watir gem. Also, you shouldn't need to require any of those other gems directly.

当ruby进程退出时,chromedriver服务停止。如果您不希望由chromedriver启动的浏览器也关闭,则需要使用分离参数。目前这是这样做的:

The chromedriver service is stopped when the ruby process exits. If you do not want the browsers that were started by chromedriver to close as well, you need to use the detach parameter. Currently this is done like so:

require 'watir'

caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps[:chrome_options] = {detach: true}
@b = Watir::Browser.new :chrome, desired_capabilities: caps

这篇关于使用watir在ruby程序完成后,Chrome浏览器会自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆