Default profile name in Chrome when using Watir-Webdriver?

六眼飞鱼酱① 提交于 2019-12-13 15:50:46

问题


I downloaded the Chromedriver then I extracted it to the right place (usr/bin), but I don't know what is the default profile name for the Chrome (Chromium) browser, so this line throw an error message:

browser = Watir::Browser.new :chrome, :profile => "default"

I tried either "current" or my username instead of "default", but none of them worked. How can I start Chrome with my default profile? Because I don't want to start a new profile without the usual preferences, and saved passwords, cookies, etc.


回答1:


I use chrome profile options to handle downloading files

download_directory = "/path/youwant/files/dowloaded/to"
profile = Selenium::WebDriver::Chrome::Profile.new 
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
b = Watir::Browser.new :chrome,  :profile => profile

see here for more info on chromedriver profile options http://src.chromium.org/svn/trunk/src/chrome/common/pref_names.cc




回答2:


You can see you default path at chrome://version/ url

In my case it is /Users/mikhail/Library/Application Support/Google/Chrome/Default

For some reason proper path would be this string without last '/Default' part of the path:

require 'watir-webdriver'

username = 'mikhail'
switches = %W[--user-data-dir=/Users/#{username}/Library/Application\ Support/Google/Chrome/]

browser = Watir::Browser.new :chrome, switches: switches
browser.goto 'google.com'



回答3:


I am not sure Chrome has that option (like Firefox has). I could not find it at http://watirwebdriver.com/chrome/



来源:https://stackoverflow.com/questions/12140822/default-profile-name-in-chrome-when-using-watir-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!