What is python's equivalent of useAutomationExtension for selenium?

我只是一个虾纸丫 提交于 2019-12-19 04:04:18

问题


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.

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


回答1:


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)



回答2:


    options = webdriver.ChromeOptions()
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=driverPath)

Above code works for me.



来源:https://stackoverflow.com/questions/45099288/what-is-pythons-equivalent-of-useautomationextension-for-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!