Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a chrome extension through Selenium WebDriver using Python

I have created a chrome extension that makes API calls to database and fetches some data relevant to a website that is currently open. For example, if I open target.com and click on extension that it will give you data relevant to target.com.

I am trying to write automated tests for it through selenium web driver which I can run on a regular basis for regression testing. To test the extension, I need to first open the extension (generally we do it by clicking on the extension icon).

I have tried different ways of attempting to click on the extension icon but have not been successful. (For example, using the keyboard shortcut ALT - LEFT_ARROW - SPACE but that does not work through webdriver).

I have also tried this (mentioned here):

options = webdriver.ChromeOptions()
options.add_argument("--app-id = mbopgmdnpcbohhpnfglgohlbhfongabi")

But above code does not help in opening extension.

I would appreciate any thoughts on how can I do this using python in Selenium Webdriver.

like image 322
curiousJ Avatar asked Aug 28 '14 20:08

curiousJ


2 Answers

You can use this solution, for simulating the click on the extension icon

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.postMessage('clicked_browser_action', '*')");
like image 194
Norayr Sargsyan Avatar answered Sep 28 '22 06:09

Norayr Sargsyan


Selenium supports interaction with web view only - so this is not possible.

I have been searching for solution to this one for some time - and it turned out there is none.

https://code.google.com/p/selenium/issues/detail?id=7805

http://grokbase.com/t/gg/selenium-developer-activity/148xndmkna/issue-7805-in-selenium-clicking-on-chrome-extension-to-open-popup

like image 37
Aleksandar Popovic Avatar answered Sep 28 '22 06:09

Aleksandar Popovic