启动Chrome浏览器时如何安装插件? [英] How to install plugin while launch the chrome browser?

查看:492
本文介绍了启动Chrome浏览器时如何安装插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用硒,黄瓜和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

步骤:

  1. 在Chrome中运行以下网址:chrome://version/
  2. 复制Chrome配置文件路径.
  3. 在Windows资源管理器中打开Chrome配置文件路径.
  4. 打开扩展程序"文件夹(安装该扩展程序时,请参阅日期和时间戳记)
  5. 复制文件夹路径.

代码:

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浏览器时如何安装插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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