是否可以使用现有的chrome用户/配置文件来配置watir Webdriver
(由chrome.exe --user-data-dir = C:\ MyChromeUserProfile创建)
在Firefox中有可能做到以下几点:
(创建与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']
虽然这会打开chrome会话,但不会使用用户的个人资料设置(特别是已安装和配置的扩展程序,例如HTTP基本身份验证的多次通过)。
顺便说一句,这是一种类似的解决方法,但对于我正在尝试实现的chrome,例如针对Firefox和自动身份验证列出的方法,网址为http://watirwebdriver.com/basic-browser-authentication/)
自问这个问题以来已经有一段时间了,但这是Google排名最高的结果,因此我将在此以最新版本的Watir(6.0.2)和Webdriver(3.0.1)进行回答。在Mac和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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句