javascript - 如何访问 webdriver 中添加的插件

标签 javascript selenium selenium-webdriver webdriver selenium-chromedriver

我已经在 chrome 中添加了一个插件,但是我如何通过 webdriver 访问它

File addonpath = new File("path of .crx file");
ChromeOptions chrome = new ChromeOptions();
chrome.addExtensions(addonpath);
WebDriver driver = new ChromeDriver(chrome );

最佳答案

您好,请按照下面的方式操作

public class ChromeProfileWithAddOn {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    // Add ChromeDriver-specific capabilities through ChromeOptions.
    // i have added this add on on chrome  = https://chrome.google.com/webstore/detail/pdf-converter/dmgnkfgleaamgbhhojkfijjmjmngokkb 
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");  
 ########paste the location of .crx file you get in step 6 here########
        options.addExtensions(new File("C:\\Users\\###\\Desktop\\hgmloofddffdnphfgcellkdfbfbjeloo.crx"));
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    System.getProperty("webdriver.chrome.driver","D:\\eclipseProject\\###\\src\\com\\###\\chromedriver_win32 (1)\\chromedriver.exe");
    ChromeDriver driver = new ChromeDriver(capabilities);
    // call chrome driver
    driver.navigate().to("chrome-extension://ldlmdngominhfffemgnfpoifladkpple/RestClient.html");
How to get above url : 
1.open the mainfest.json file there you will find  "local_path":"RestClient.html"
2. make sure your extension is installed in chrome and then 
3. go to chrome://extensions/ (follow steps-3 and 4 below)
4. you will get an ID value as shown in the image just below step 4 copy that
5. now u can make your url as "chrome-extension://ID/local_path"
6. now open it in chrome browser
} }

代码如上,但我们必须遵循一些基本步骤:

注意:我说的是以下 ** CHROME** 的高级 REST 客户端 示例:https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

第一步:

 `Please download or if in-case already present go to the extension's manifest.json file` 

如果您想在本地驱动器上下载附加组件,请按照以下步骤操作:

a.> 下载此扩展 https://chrome.google.com/webstore/detail/chrome-extension-source-v/jifpbeccnghkjeaalbbjmodiffmgedin

b.> 安装它(在 chrome 浏览器的右上角会出现一个 CRX 按钮)

c.> 现在在 chrome 网上应用店 中搜索 Advanced REST client 或直接将链接复制并粘贴到浏览器中

https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

d.> 点击 CRX 图像/按钮,您将获得两个选项 enter image description here

选择下载为 zip(将其保存在您喜欢的位置)。

e.>解压

f.> 在解压后的文件夹中你会找到ma​​nifest.json 文件

第 2 步:

Copy the location of mainfest.json file 

第 3 步:转到 Chrome 浏览器并在 url 中输入

 chrome://extensions/  

这里会显示所有已安装的插件/扩展

第 4 步:

please check the Developer option

Pack Extension 选项现在可见

enter image description here

第 5 步: 单击 Pack Extension 并在 Extension root directory 下:(第一个选项)粘贴 ma​​nifest.json 文件的位置。 enter image description here

第 6 步:如果您按照上述所有操作进行操作,您将获得此 enter image description here

希望这能解决您的问题。

关于javascript - 如何访问 webdriver 中添加的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36276736/

相关文章:

javascript - arcTo 有时不会在调整大小时绘制

node.js - 如何检查元素是否不存在 selenium nodejs

java - 即使 xpath 相同,如何识别 Selenium 中的元素

java - 当 marionette 通过 Selenium 3.12.0 变为 false 时,无法找到与 Firefox 匹配的功能集

java - WebDriver 等待 JQuery 完成

Java-Selenium 2 : Chromedriver - Exception calling driver. 管理().window().setPosition()

javascript - 使用直接输出将 JSON 从 PHP 传递到 Javascript

javascript - 多个 React-Native 组件的可重用动画

python - 滚动高度在 Selenium : [ arguments[0]. scrollHeight 中返回 "None"]

javascript - node.js ~ 构建 Promise resolves 的链式序列