如何通过 Ruby Selenium Binding(或 WATIR)创建 chrome 配置文件 [英] How to create chrome profile via Ruby Selenium Binding(or WATIR)

查看:42
本文介绍了如何通过 Ruby Selenium Binding(或 WATIR)创建 chrome 配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何为 Firefox 创建配置文件

I know how to create profile for Firefox

require 'watir'
options = Selenium::WebDriver::Firefox::Options.new
options.profile = "default"
@driver = Selenium::WebDriver.for :firefox, options: options
@b = Watir::Browser.new @driver

但是当我为 Chrome 做同样的事情时它没有创建,事实上我意识到选项(请看上面)对象甚至没有方法 profile= 所以我尝试添加像给定的配置文件下面(我看到人们是如何在 Java Selenium Binding 中创建的,所以我做了同样的事情,但在这里不起作用)

But when I do same thing for Chrome it's not creating, Infact I realized that options(please look above) object doesn't even have the method profile= so I try adding profile like as given below(I saw how people are creating in Java Selenium Binding so I have done the same but it's not working here)

options = Selenium::WebDriver::Firefox::Options.new
options.add_argument('user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default')
@driver = Selenium::WebDriver.for :chrome, options: options

有人可以帮助我如何通过 Ruby Selenium 绑定(或 WATIR)创建 Chrome 配置文件吗?

Can someone help me how to create Chrome Profile via Ruby Selenium binding(or WATIR)?

推荐答案

可以通过 Chromedrivers 的 user-data-dir 参数使用现有配置文件或创建新配置文件.在 Watir 中,您可以通过 :args 参数传递参数:

Using an existing or creating a new profile can be done via Chromedrivers user-data-dir argument. In Watir, you can pass the argument via the :args parameter:

browser = Watir::Browser.new :chrome, 
  args: ['user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data']

请注意,如果您尝试使用现有的默认配置文件,您不希望在路径中包含默认"目录.

Note that if you trying to use the existing default profile, you do not want to include the "Default" directory in the path.

这篇关于如何通过 Ruby Selenium Binding(或 WATIR)创建 chrome 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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