6

我要的只是从网上商店加载铬扩展。 我做了很多搜索找出来,但只知道我们可以从本地机器加载扩展。 我真的不知道硒是否具有从网上商店或网址加载扩展功能。使用硒加载铬扩展

请让我知道我在尝试使用硒是可能的吗?

+0

一个选项是使用java从webstore下载每次运行测试脚本时的crx文件,然后将下载的脚本加载到chromeoptions中。 Java中有很多选项可以从互联网下载文件。你的方法可以接受吗? – parishodak

+0

是的,即使从商店下载扩展,然后安装它也会。但我不确定我们是否可以下载CRX文件?我们有可用的下载网址吗? –

回答

7

我不确定你为什么特别从Webstore下载并安装到Chrome中。

我发现了一些步骤,以下载Chrome扩展:

- 随着连接到互联网的计算机上,安装在扩展页扩展:https://chrome.google.com/webstore/detail/
-Navigate到扩展的源代码。在XP中可以找到:C:\ Documents and Settings \\ Local Settings \ Application Data \ Google \ Chrome \ User Data \ Default \ Extensions \
- 您应该看到一个版本文件夹(即“0.0.21_0”) 。复制此文件夹并将其移动到要安装的计算机上。
- 打开了镀铬的断开连接的计算机上,然后转到扳手 - >工具 - >扩展
- 单击旁边的+号开发模式以显示开发者选项
- 点击“打包扩展程序...”,然后选择版本文件夹作为根目录。将私钥文件留空。这将在版本文件夹中创建一个.crx文件以及一个私钥,就像您是开发人员一样。 。

- 或 -

1-找到你感兴趣的扩展的ID当扩展的详细信息页面,这将是这样的: bfbmjmiodbnnpllbbbfblcplfjjepjdn 后 https://chrome.google.com/webstore/detail/

2-粘贴到这一点的任何其他浏览器(未铬): https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D~~~~%26uc

3-和与延伸ID替换~~~~。 系统会提示您保存CRX文件。将此文件拖到Chrome窗口并继续安装。

来源:https://productforums.google.com/forum/#!topic/chrome/g02KlhK12fU

最后,使用ChromeOptions下载.crx档案加载扩展

ChromeOptions options = new ChromeOptions(); 
options.addExtensions(new File("/path/to/extension.crx")); 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
ChromeDriver driver = new ChromeDriver(capabilities); 

来源:https://sites.google.com/a/chromium.org/chromedriver/extensions

+0

谢谢parishodak。 我使用JS返回了给定ID的下载URL。 –

+0

我使用JS返回了给定ID的下载URL。我的最终目标是拦截来自diff扩展名的请求。为此,我使用'chrome.webRequest.onBeforeRequest'API的另一个扩展来捕获请求。但似乎chrome不会将请求扩展到我的处理程序。我可以使用的另一个API是'chrome.devtools.network.onRequestFinished',但它只在开发者工具打开时才起作用。现在我坚持如何使用Selenium打开开发人员工具?你可以通过通讯方式来跟踪来自不同分机的请求吗? –

+0

并不真正熟悉Chrome扩展开发。参考这篇文章http://stackoverflow.com/questions/23825371/running-a-chrome-extension-from-selenium-webdriver关于修改扩展,以包括用户在javascript中的动作。不知道它是否有帮助 – parishodak

1

不知道为什么,但有人删除了他们的答案,这是正确的。以下是内容(从@parishodak来源):

ChromeOptions options = new ChromeOptions(); 
options.addExtensions(new File("/path/to/extension.crx")); 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
ChromeDriver driver = new ChromeDriver(capabilities); 

这个特殊的例子是在Java中

2
  1. 认沽chromedriver EXE在你的文档文件,如果你想遵循这一点,有一个成功的结果。

  2. 从Google下载“GET CRX”扩展程序。

  3. 下载你的扩展(即我的Rest API测试是“DHS”)。

  4. 转到Chrome网上应用店>>搜索你的扩展>>右键单击它,然后点击:: GET CRX
    (这应该下载CRX文件(你已经下载了一个)。对于我来说, CRX文件是“extension_1_2_5.crx”)

  5. 在任何Chrome窗口中删除CRX文件(这可以拒绝它,但不用担心)。

  6. 现在,构建测试和执行

    public static void openChromeExtension(){ 
    
        System.setProperty("webdriver.chrome.driver", "/Users/[your local name]/Documents/chromedriver"); 
    
        ChromeOptions options = new ChromeOptions(); 
        options.addExtensions(new File("/Users/[your local name]/Documents/extension_1_2_5.crx")); 
    
        DesiredCapabilities capabilities = new DesiredCapabilities(); 
        capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
        ChromeDriver driver = new ChromeDriver(capabilities); 
        System.out.println("Opening extension"); 
        driver.get("chrome-extension://**aejoelaoggembcahagimdiliamlcdmfm**/dhc.html"); 
    
        driver.navigate().refresh(); 
        System.out.println("Refresh successfully"); 
    } 
    

    //这是扩展URL,或者你可以得到的镀铬标识://扩展/找到扩展和复制ID。但是,该网址必须是扩展名网址。

+0

它给我的文件是。bin文件不是.crx文件。这是正常的吗? – MattClimbs

0
using System.IO; 
using System.IO.Compression; 



    public static class ChromeExtension 
     { 
      public static string Execute() 
      { 
       var ParentPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent; 
       var DirectoryPath = ParentPath.FullName.Remove(ParentPath.FullName.IndexOf(ParentPath.Name)); 

       string startPath = $"{DirectoryPath}\\Exchanger\\ChromeExtension"; 
       string zipPath = $"{DirectoryPath}Exchanger\\Extension.zip"; 

       if (System.IO.File.Exists(zipPath)) 
       { 
        System.IO.File.Delete(startPath); 
       } 

       ZipFile.CreateFromDirectory(startPath, zipPath); 


       if (System.IO.File.Exists($"{DirectoryPath}\\Exchanger\\Extension.crx")) 
       { 
        System.IO.File.Delete($"{DirectoryPath}\\Exchanger\\Extension.crx"); 
       } 

       System.IO.File.Move(zipPath, $"{DirectoryPath}\\Exchanger\\Extension.crx"); 

       return $"{DirectoryPath}\\Exchanger\\Extension.crx"; 
      } 

     } 

.... //// ....

Used: 
var options = new ChromeOptions(); 
options.AddExtension(ChromeExtension.Execute()); 

....////.... 
0

虽然技术上声音意图并不总是有效的解决方案上面,所以我想另一种方式来做到这一点。 因为很多时候我需要很多的东西,更好地手动完成,认证,某些饼干等

我使用的文件夹,配置文件,我跑:

chrome_options = Options() 
chrome_options.add_argument("user-data-dir=selenium") 
driver = webdriver.Chrome(chrome_options=chrome_options) 
driver.get("www.google.com") 

然后手动安装的扩展和做在登录现在我需要的每次我开始用的webdriver该文件夹的一切都在那里

chrome_options = Options() 
chrome_options.add_argument("user-data-dir=selenium") 
driver = webdriver.Chrome(chrome_options=chrome_options) 
driver.get("www.google.com") #Now you can see the Extensions and the logins done are present 

的好处是,你可以使用不同的设置和扩展多个文件夹,而不需要安装和卸载EXTENS离子,更改设置,更改登录等