且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用watir在ruby程序完成后,Chrome浏览器会自动关闭

更新时间:2022-12-01 20:51:17

首先,不推荐使用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