How to install plugin while launch the chrome browser?(如何在启动 chrome 浏览器时安装插件?)
问题描述
我正在使用 selenium、cucumber 和 java 进行自动化测试.
I am using selenium,cucumber and java for automation testing.
我需要在 chrome 浏览器中安装插件才能打开我的应用程序.这个插件我已经安装了.但是当我通过 selenium 打开 chrome 浏览器时,这个插件丢失并且应用程序无法正常工作.
I have a requirement of installing a plugin to the chrome browser to open my application. This plugin I have already installed. But when I open the chrome browser through selenium this plugin is missing and application is not working.
每次打开浏览器时如何安装插件?
How to install the plugin each time when the browser is opening?
推荐答案
我正在使用 Chrome 65.0 和 Selenium 3.11.0
步骤:
- 在 Chrome 中运行以下 URL:chrome://version/
- 复制 Chrome 配置文件路径.
- 在 Windows 资源管理器中打开 Chrome 配置文件路径.
- 打开扩展文件夹(查看安装扩展时的日期和时间戳)
- 复制文件夹路径.
代码:
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", "F:\Automation\chromedriver.exe");
String pathToExtension = "C:\Users\USER_DELL_2014_07\AppData\Local\Google\Chrome\User Data\Profile 3\Extensions\bhlhnicpbhignbdhedgjhgdocnmhomnp\2.0_0";
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=" + pathToExtension);
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
就是这样!您可以使用此代码,chrome 将使用给定的扩展名进行实例化
That's it! You can use this code and chrome would be instantiated with the given extension
如果您对此有任何疑虑,请告诉我.
Please let me know if you have any concerns related to this.
这篇关于如何在启动 chrome 浏览器时安装插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在启动 chrome 浏览器时安装插件?
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
