I'm wondering if there is a way to click on an extension button with Selenium without using win32api. Here's the image, in the black circle is the extension icon which I'd want to click.
That icon is located in the toolbar, so I don' know if there's a way to look for it with Selenium.

- 453
- 3
- 6
- 18
5 Answers
First install pyautogui
then find an image of the extension icon and save it on your computer in some location like ./extn_icon.png
. Then use the following code to click on the extension:
import pyautogui
img_location = pyautogui.locateOnScreen(image_path, confidence=0.5)
image_location_point = pyautogui.center(img_location)
x, y = image_location_point
pyautogui.click(x, y)

- 1,178
- 2
- 12
- 26
No, It is not possible with Selenium. The only way to achieve what you want to do is to use any automation tool that actually runs directly in the OS that you use.

- 683
- 5
- 15
Below is the solution is in Python with pyautogui.
Pre-Condition:
save the extension image in the project folder (I saved it under "autogui_ref_snaps" folder in my example with "capture_full_screenshot.png" name
Imports needed
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from Common_Methods.GenericMethods import *
import pyautogui #<== need this to click on extension
Script:
options = ChromeOptions()
options.add_argument("--load-extension=" + r"C:\Users\supputuri\AppData\Local\Google\Chrome\User Data\Default\Extensions\fdpohaocaechififmbbbbbknoalclacl\5.1_0") #<== loading unpacked extension
driver = webdriver.Chrome(
executable_path=os.path.join(chrome_options=options)
url = "https://google.com/"
driver.get(url)
# get the extension box
extn = pyautogui.locateOnScreen(os.path.join(GenericMethods.get_full_path_to_folder('autogui_ref_snaps') + "/capture_full_screenshot.png"))
# click on extension
pyautogui.click(x=extn[0],y=extn[1],clicks=1,interval=0.0,button="left")
If you are loading an extension and it's not available in incognito mode then follow my answer in here to enable it.

- 13,644
- 2
- 21
- 39
-
Can you give some information on "Common_Methods.GenericMethods", i can't seem to find it – Tbaki Apr 02 '21 at 21:11
-
how to I download the extension image? – Moran Reznik May 30 '22 at 20:02
You could work around this by using this link with selenium. The behavior might be slightly different, however.
chrome-extension://<the extension identity>/html/login.html
Visit this link to get extension identity: How to get extension identity

- 352
- 4
- 15
-
extension id in my case is "dkgjopcolgcafhnicdahjemapkniikeh" . when I go to that link, it just says your file was not found. Is there maybe a way to activate the extension instead of using Selenium clicking? – DoctorEvil Jul 25 '18 at 19:13
i am facing the same problem but i am able to do it with sikuli. its very easy to use this and you can find the jar in maven repository for this

- 11
- 1
-
3Please don't just post some tool or library as an answer. At least demonstrate [how it solves the problem](http://meta.stackoverflow.com/a/251605) in the answer itself. – Yunnosch Sep 05 '20 at 07:54