Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is python's equivalent of useAutomationExtension for selenium?

I am trying to run a basic selenium script from my office environment, which has a proxy and firewall setup. The script is running fine except before every execution it gives a popup saying "Loading of unpacked extensions is disabled by administrator." Which means I'll have to manually click it to proceed and that defies the purpose of automation. enter image description here

I googled and stackoverflowed the error and looks like there is a chrome option useAutomationExtension that needs to be disabled. I went on search of the right syntax for python( Environment: Python 2.7-win32, running the chrome driver 2.30.477700(0057494ad8732195794a7b32078424f92a5fce41)) but couldn't find the proper chrome switch/option.

I also looked into this: Chromium/Chrome switches from google: https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc and Peter's list of chrom switches: https://peter.sh/experiments/chromium-command-line-switches/

I vaguely tried chrome_options.add_argument('--disable-useAutomationExtension') but that didn't help either.

So, I need your guidance and suggestions on this. Please help.

Code_part:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re, os

from selenium.webdriver.chrome.options import Options


class Sel(unittest.TestCase):
    def setUp(self):
        # self.driver = webdriver.Firefox()

        # Clean existing file before starting
        #############################################
        dlpath = "C:\Users\Baba\blacksheep_tracker.xlsm"

        if os.path.exists(dlpath):
            os.remove(dlpath)

        ############################################

        chrome_options = Options()
        chrome_options.add_argument("--cipher-suite-blacklist=0x0039,0x0033")
        chrome_options.add_argument("--disable-extensions")
        chrome_options.add_argument('--start-maximized')
        chrome_options.add_argument('--disable-useAutomationExtension')
        self.driver = webdriver.Chrome(chrome_options=chrome_options)

        self.driver.implicitly_wait(30)
        self.base_url = "https://monsanto365.sharepoint.com/teams/XYZ_Tracker.xlsm"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_sel(self):
        driver = self.driver
        ## Launch the download url and wait for the download to complete
        driver.get("https://monsanto365.sharepoint.com/teams/xyz_tracker.xlsm")
        print 'Loading complete'
        time.sleep(30)
        print '30 sec over'

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e:
            return False
        return True

    def is_alert_present(self):
        try:
            self.driver.switch_to_alert()
        except NoAlertPresentException, e:
            return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally:
            self.accept_next_alert = True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)


if __name__ == "__main__":
    unittest.main()

Edit: I am also aware of official google answer for this issue that they are working on it and it has something to do with devtools command and stuff. As it's taking forever I'm looking for any temporary solution or suggestion. Link: https://bugs.chromium.org/p/chromedriver/issues/detail?id=639

like image 428
S4nd33p Avatar asked Dec 02 '22 12:12

S4nd33p


1 Answers

The driver installs an extension in Chrome to implement some features like taking a screenshot.

It's possible to disable it with the useAutomationExtension option:

from selenium import webdriver

capabilities = {
  'browserName': 'chrome',
  'chromeOptions':  {
    'useAutomationExtension': False,
    'forceDevToolsScreenshot': True,
    'args': ['--start-maximized', '--disable-infobars']
  }
}    

driver = webdriver.Chrome(desired_capabilities=capabilities)
like image 162
Florent B. Avatar answered Dec 21 '22 12:12

Florent B.