2

I'm trying to run chromedriver with this plugin. I downloaded the plugin as .crx and I initialized browser with this extension:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension('/path/to/extension.crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path='/path/to/chromedriver')

The extension is correctly loaded in browser but is not enabled.

not enabled extension screenshot

In order to enable the extension you have to click the extension icon which is outside of DOM.

enabled extension

Is there any way to perform this kind of action.

Panagiotis Simakis
  • 1,245
  • 1
  • 18
  • 45
  • 1
    Have your tried with configuring the extension enbale settings in a common profile and loading the profile using ChromeOptions? – Ashok kumar Ganesan Jul 18 '18 at 12:22
  • No, I haven't tried this yet but sounds pretty clever. Is it possible to start `chromedriver` and use specific google account as chrome account? – Panagiotis Simakis Jul 18 '18 at 12:32
  • I am not aware of it. – Ashok kumar Ganesan Jul 18 '18 at 12:53
  • I tried the same with a different extension and it's by default enabled for me. Can you try it with a different extension. When you use `AddExtension` method, it should be by default enabled, unless you have other switches like `--disable-extension` added in code. – Raj Jul 21 '18 at 07:36

2 Answers2

1

This cannot be done via Selenium. One quick way to do this would be to use win32 api to simulate a click on the coordinates of your extension button on your screen.

First of all find the coordinate of the extension button on your screen. You can use tool like this. I, myself found a rough idea of the location by comparing to the coordinate of my DOM immediately below the button through this chrome extension.

Then, use below code to simulate a click on that location:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import win32api, win32con

chrome_options = Options()
chrome_options.add_extension('//path to crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path='path to chromedriver')
driver.maximize_window()
click(1317,51) # the coordinates of the button on my 1366 x 768 screen after maximizing. 

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Additionally you can check out Sikuli. It uses image recognition to identify and perform actions on any desired element on the screen. You first have to take the screenshot of your button and then perform a click function on it inside your sikuli script. After that, you can trigger your sikuli script from python by following suggestions from here.

Shivam Mishra
  • 1,731
  • 2
  • 11
  • 29
0

Nothing is worked for me on Ubuntu(Linux). So I had done with this


Installation of required packages:
-> sudo apt install libx11-dev
Note: install above "libx" package according to your distro

-> pip install selenium PyUserInput

Note: After installing PyUserInput, you should have pymouse and pykeyboard modules in your python path.

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pymouse import PyMouse

m = PyMouse()
executable_path = "/home/username/python/chromedriver"
# Note: replace your chromedriver path with above

os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension('path_of_extension.crx')

driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.maximize_window()

m.click(1317,51)

Thanks

Manindra Gautam
  • 387
  • 3
  • 8