且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在启动 chrome 浏览器时安装插件?

更新时间:2022-11-18 19:49:19

我正在使用 Chrome 65.0Selenium 3.11.0

步骤:

  1. 在 Chrome 中运行以下 URL: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.