selenium - 如何使用 Webdriver.io 打开特定的 Chrome 配置文件?

标签 selenium selenium-webdriver webdriver selenium-chromedriver

我正在使用 webdriver.io使用节点脚本打开浏览器实例。浏览器打开,但它忽略了 desiredCapabilities 对象中定义的一些选项。这是我现在的配置:

const path = require('path');
const webdriver = require('webdriverio');

const INIT_URL = 'http://www.google.ca';

const options = {
  desiredCapabilities: {
    browserName: 'chrome',
    applicationCacheEnabled: false,
    chromeOptions: {
      args: [
        'disable-web-security',
        'allow-running-insecure-content',
        'auto-open-devtools-for-tabs',
        'user-data-dir=/Users/david/Library/Application\ Support/Google/Chrome/Profile\ 2'
      ]
    }
  }
};

const browser = webdriver
  .remote(options)
  .init()
  .url(INIT_URL);

除了 user-data-dir 之外,所有选项似乎都有效。浏览器实例打开但未使用提供的配置文件。

有没有办法使用 Webdriver.io (NodeJS) 配置 Selenium 以选择实际有效的特定浏览器配置文件?

更新

来自@FlorentB。建议我试过双引号和双反斜杠,但没有成功:

  • 'user-data-dir="/Users/david/Library/Application\Support/Google/Chrome/Profile\2"'
  • 'user-data-dir=/Users/david/Library/Application\\Support/Google/Chrome/Profile\\2'

但我还注意到,当我看到由 Selenium 打开的 Chrome 实例的可用配置文件时,列表是空的:

Empty profile list

但是当我打开一个普通的 Chrome 实例时(手动,没有 Selenium)我确实看到了我的两个可用配置文件:

Normal profile list

最佳答案

在公司人员的帮助下,我找到了自己问题的解决方案。我必须像这样将属性 user-data-dirprofile-directory 结合起来:

const options = {
  desiredCapabilities: {
    browserName: 'chrome',
    applicationCacheEnabled: false,
    chromeOptions: {
      args: [
        'disable-web-security',
        'allow-running-insecure-content',
        'user-data-dir=/Users/david/Library/Application\ Support/Google/Chrome',
        'profile-directory=Profile\ 2',
      ]
    }
  },
};

关于selenium - 如何使用 Webdriver.io 打开特定的 Chrome 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983855/

相关文章:

javascript - Protractor - 将链接存储在列表中并随机单击

单击不同窗口时,selenium webdriver 停止工作

ruby - watir splash 中的页面对象——如何确保正确的页面对象被实例化

ruby - 安装 watir-webdriver 时遇到问题,因为 Ruby 版本不是 >= 2.0 (Ubuntu)

javascript - 使用 ng-show 属性测试 <span> 是否可见

linux - headless with rails selenium-webdriver 通过 linux 服务器获取网页屏幕

java - Selenium - 确定 Angular 2+ 中网页是否已完成加载

java - 选择复选框时在 katalon 中出现过时元素异常

css - Selenium Python 我正在尝试使用 XPATH 或 CSS 选择器从嵌套的 span 标记中选择一个下拉列表

java - 在 Selenium WebDriver 中打开新选项卡后,如何使其成为浏览器中的可见/Activity 选项卡?