如何配置'watir'以使用现有的chrome用户配置文件(使用chrome.exe --user-data-dir创建) [英] How to configure 'watir' to use an existing chrome user profile (created with chrome.exe --user-data-dir)
问题描述
是否可以使用现有的chrome用户/配置文件配置watir Webdriver
Is it possible to configure watir webdriver use an existing chrome user/profile
(由chrome.exe创建--user-data-dir = C:\ MyChromeUserProfile )
在 Firefox 中,可以执行以下操作:
(使用firefox -P 创建了一个用户个人资料)
profile = Selenium::WebDriver::Firefox::Profile.new(c://MyFFUserProfile)
Watir::Browser.new :ff, :profile => profile
In Firefox it's possible to do the following:
(created a user profile with firefox -P) profile = Selenium::WebDriver::Firefox::Profile.new(c://MyFFUserProfile)
Watir::Browser.new :ff, :profile => profile
对于 Chrome ,我尝试使用以下代码无济于事:
Watir::Browser.new :chrome, :switches => %w['--user-data-dir=c://MyChromeUserProfile']
For Chrome, I tried the following code to no avail:
Watir::Browser.new :chrome, :switches => %w['--user-data-dir=c://MyChromeUserProfile']
虽然这会打开chrome会话,但不会使用用户的个人资料设置(特别是已安装和配置的扩展程序,例如HTTP基本身份验证的多次通过).
While this opens a chrome session, it does not use the user's profile settings (Specifically an extension that was installed and configured, like Multi-pass for HTTP basic authentication).
通过这种方式,这是一个类似的解决方法,但对于我正在尝试实现的chrome,例如
By the way this is a similar workaround but for chrome that I am trying to implement like the one listed for Firefox and auto auth posted on http://watirwebdriver.com/basic-browser-authentication/)
推荐答案
问了这个问题已经有一段时间了,但这是Google排名最高的结果,因此我将在此以最新的两个Watir(6.0 .2)和Webdriver(3.0.1).在Mac和Windows上适用于我:
It's been a while since this question was asked but it is the top ranked Google result so I'll answer it here with the newest release of both Watir (6.0.2) and Webdriver (3.0.1). This works for me on Mac and Windows:
require 'watir'
switches = %W[--user-data-dir=c:\\chrome]
# switches = %W[--user-data-dir=/chrome] => Linux or Mac
prefs = {
:download => {
:prompt_for_download => false,
:default_directory => "c:\\downloads"
}
}
browser = Watir::Browser.new :chrome, :prefs => prefs, switches: switches
browser.goto 'google.com'
browser.text_field(title: 'Search').set 'Hello World!'
browser.button(type: 'submit').click
sleep 10
puts browser.title
browser.close
这篇关于如何配置'watir'以使用现有的chrome用户配置文件(使用chrome.exe --user-data-dir创建)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!