0

I have successfully added an the private internet access extension to my selenium.

How do I click on the little extension icon on the top right hand corner? Upon clicking this icon it opens a small pop up (refer to screenshot). Then type in my username and password, then click login.

Not asking for someone to code the entire thing for me, I would just like to know how to get started and how to interact with the extension. I can't use xPath because I can't see the div in the inspect element (to right-click and copy xPath)

Link to a screenshot so you understand better

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

path_to_extension = '2.0.2_0'

chrome_options = Options()
chrome_options.add_argument('load-extension=' + path_to_extension)


driver = webdriver.Chrome(chrome_options=chrome_options)
driver.create_options()
driver.get("http://www.google.com") 
Alex
  • 73
  • 7
  • Sounds like something very basic that should have an existing solution. Probably [Selenium: Opening an extension's popup window](//stackoverflow.com/q/49943354) – wOxxOm Apr 12 '19 at 07:56
  • @wOxxOm That is in java. My question is in python. Also `CTRL+SHIFT+Y` doesn't work and I cannot go to the extension webpage, because the extension is a pop up only. – Alex Apr 12 '19 at 07:57
  • see [here](https://stackoverflow.com/questions/51288093/python-selenium-chrome-extension-settings-not-loading-using-a-crx-file) @Alex **isn't this what you were looking for** ? –  Apr 12 '19 at 08:05
  • If we are all so stupid and can't understand that you just want to click into the extension and send keystrokes to fill the window, use `pyautogui` to find the icon of the extension and the user, password fields and send the credentials that way. –  Apr 12 '19 at 08:07
  • The principle is the same. You can specify the hotkey in the extension's manifest. You can open the popup directly by using chrome-extension://id/path/to/popup.html. – wOxxOm Apr 12 '19 at 08:09
  • @wOxxOm So how do I actually get the path/url of the pop up? If I am able to open the pop up in a tab, then this solves my problem. When I right-click > inspect on the pop up, a window opens and closed within a fraction of a second – Alex Apr 12 '19 at 08:10
  • Right-click the popup and click ”inspect” - you'll see the path in devtools title or by running `location` in the console. BTW found a better existing thread [here](https://stackoverflow.com/questions/25557533/open-a-chrome-extension-through-selenium-webdriver-using-python). – wOxxOm Apr 12 '19 at 08:12
  • Another approach is to use the path specified in manifest.json's browser_action. – wOxxOm Apr 12 '19 at 08:13
  • @wOxxOm When I click inspect, it opens a window and closes it almost instantly (so I can't see any path). I tried for other extensions, I can see the path (and see the pop up). However for private internet access I cannot. I also tried going to the mainiest.json. I tried to visit all the url's in there. No pop up url's – Alex Apr 12 '19 at 08:20
  • It's there. The actual URL will be chrome-extension://id/html/foreground.html where `id` is the actual id of the extension. – wOxxOm Apr 12 '19 at 08:26
  • @wOxxOm I am so confused how it worked now. I tried the `js/background.js` and `html/foreground.html` but it didn't work. Then I tried it again, after you made the comment and it worked... I thought that was the end of the problem... Looks like I can't even inspect element this page/get any xPaths. It some how automatically closes the tab if you try to do anything – Alex Apr 12 '19 at 08:31
  • @wOxxOm This is some next level html coding... You literally cannot touch anything. You cannot save the html page, you cannot even click. You cannot even switch tabs. as soon as it detects you are trying to do something to view the code, it closes – Alex Apr 12 '19 at 08:43

0 Answers0