【问题标题】:How to access added plugins in webdriver如何在 webdriver 中访问添加的插件
【发布时间】:2016-07-16 13:29:21
【问题描述】:

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

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

【问题讨论】:

标签: javascript selenium selenium-webdriver webdriver selenium-chromedriver


【解决方案1】:

您好,请按照以下方式进行操作

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
} }

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

注意:我说的是 Advanced REST client 的示例,用于 ** CHROME** 网址如下:https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

第 1 步:

 `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 客户端,或者直接将链接复制并粘贴到浏览器中

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

d.>点击CRX图片/按钮,你会得到两个选项

选择以 zip 格式下载(将其保存在您的首选位置)。

e.>解压

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

第二步:

Copy the location of mainfest.json file 

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

 chrome://extensions/  

这里将显示所有已安装的附加/扩展程序

第四步:

please check the Developer option

Pack Extension 选项现在可见

第 5 步: 点击Pack Extension,在Extension根目录下:(第一个选项)粘贴ma​​nifest.json文件的位置。

第 6 步:如果您已按照上述所有操作,您将获得此

希望这能解决您的问题。

【讨论】:

  • 我可以安装@raj,但在测试执行期间如何访问
  • 您好,请查看更新答案及其工作原理。请逐步进行操作。
  • 这似乎完全忽略了 OP 的(模糊)点:他如何“访问”一个已经安装的插件?这似乎是在费力地详细说明如何安装,然后获取插件自己的 URL,这似乎完全没有意义。你们俩都需要提前明确要求是什么。
  • @ Andrew Regan 我试图告诉 **1.**如何使用 selenium 和 **2.** 在 google chrome 实例上安装新的扩展/附加组件。然后如何访问那。这就是“如何在 webdriver 中访问添加的插件”的问题
  • (1) 他已经知道怎么做; (2) 在 OP 澄清他所说的“访问”是什么意思之前,猜测他想要那个特定的 URL 是不好的。希望如果他编辑他的帖子以阐明他如何“使用”扩展程序,您可以调整您的答案以适应。
猜你喜欢
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
  • 2021-01-11
  • 1970-01-01
  • 1970-01-01
  • 2015-07-17
  • 1970-01-01
相关资源
最近更新 更多