Install/Add chrome extension from Chrome Web Store using Selenium

跟風遠走 提交于 2019-12-13 02:36:31

问题


I am developing test automation using Selenium with Java. I would like to install/add extension to chrome instance launched through Selenium. One way to install/add extension is using .crx file as follow.

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(ext_path));

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

driver = new ChromeDriver(capabilities);

But I would like to install/add extension from Chrome Web Store. Can anyone please suggest how to achieve this. Thanks.


回答1:


You can install extension (packed/unpacked) to chrome with options.addExtensions/addArguments as mentioned here:- https://sites.google.com/a/chromium.org/chromedriver/extensions

alternative: Chromedriver every time opens new chrome instance with temporary profile for the execution. To avoid this you can use existing profile with desired chrome extension installed OR you can send commands to already running instance of chrome which has desir d extension installed.

usually, inline/webstore installation of a Chrome extension can't be tested with ChromeDriver/Selenium alone, because of confirmation dialog. you can use platform-specific hacks to click on the button (e.g. via AutoIt),



来源:https://stackoverflow.com/questions/34194674/install-add-chrome-extension-from-chrome-web-store-using-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!