使用 selenium 加载 chrome 扩展 [英] Load chrome extension using selenium
问题描述
在运行 selenium 时,我需要从网上商店加载 chrome 扩展.在我的研究中,我只发现了如何从本地机器加载扩展.
While running selenium, I need to load a chrome extension from the web store. In my research, I only found how to load an extension from the local machine.
selenium 是否可以从 Web Store 加载扩展程序?
推荐答案
我不知道您为什么特别喜欢从 Webstore 下载然后安装到 Chrome 中.
I am not sure why you are particular about downloading from Webstore and then install into Chrome.
我找到了一些下载 chrome 扩展程序的步骤:
I found some steps to download chrome extensions:
-将计算机连接到 Internet,从扩展程序页面安装扩展程序:https://chrome.google.com/webstore/detail/
- 导航到扩展源代码.在 XP 中,它位于:C:Documents and Settings\Local SettingsApplication DataGoogleChromeUser DataDefaultExtensions
- 您应该会看到一个版本文件夹(即0.0.21_0").复制此文件夹并将其移动到您要安装的计算机上.
- 在断开连接的机器上打开 chrome 并转到扳手 -> 工具 -> 扩展
- 单击开发人员模式旁边的 + 以显示开发人员选项
- 单击Pack extension..."并选择版本文件夹作为根目录.将私钥文件留空.这将在版本文件夹中创建一个 .crx 文件以及一个私钥,就像您是开发人员一样.
-With a computer connected to the internet, install the extension from the extension page: https://chrome.google.com/webstore/detail/
-Navigate to the extension source code. In XP this is found at: C:Documents and Settings\Local SettingsApplication DataGoogleChromeUser DataDefaultExtensions
-You should see a version folder (ie. "0.0.21_0"). Copy this folder and move it on the machine you want to install on.
-Open up chrome on the disconnected machine and go to Wrench -> Tools -> Extensions
-Click the + next to Developer mode to display the developer options
-Click 'Pack extension...' and choose the version folder as the root directory. Leave the private key file blank. This will create a .crx file in the version folder along with a private key as if you were the developer.
--或--
1- 找到您感兴趣的扩展程序的 ID.在扩展程序的详细信息页面上,它会是这样的:bfbmjmiodbnnpllbbbfblcplfjjepjdn后https://chrome.google.com/webstore/detail/
1- Find the ID of the extension you’re interested in. When on the details page of the extension, it will be something like : bfbmjmiodbnnpllbbbfblcplfjjepjdn after https://chrome.google.com/webstore/detail/
2- 将其粘贴到任何其他浏览器(非 Chrome)中:https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D~~~~%26uc
2- Paste this into any other browser (not Chrome): https://clients2.google.com/service/update2/crx?response=redirect&x=id%3D~~~~%26uc
3- 并用扩展 ID 替换 ~~~~ .系统会提示您保存 CRX 文件.将此文件拖到 Chrome 窗口并继续安装.
3- and replacing ~~~~ with the extension ID. You’ll be prompted to save a CRX file. Drag this file to a Chrome window and proceed with installation.
来源:https://productforums.google.com/forum/#!主题/chrome/g02KlhK12fU
最后使用ChromeOptions中下载的.crx文件加载扩展
Finally, use the downloaded .crx file in ChromeOptions to load the extension
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
这篇关于使用 selenium 加载 chrome 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!