python硒的useAutomationExtension等价于什么?

发布于 2021-01-29 16:20:11

我正在尝试从办公室环境中运行基本的硒脚本,该脚本具有代理和防火墙设置。该脚本运行良好,除非在每次执行之前它都会弹出一个窗口,提示“管理员已禁用解压缩扩展的加载”。这意味着我必须手动单击它才能继续进行,这违背了自动化的目的。
在此处输入图片说明

我用谷歌搜索并且堆栈溢出了错误,看起来好像有一个chrome选项useAutomationExtension需要被禁用。我继续寻找适用于python的正确语法(环境:Python
2.7-win32,运行chrome驱动程序2.30.477700(0057494ad8732195794a7b32078424f92a5fce41)),但找不到合适的chrome开关/选项。

我也看了这个:铬/
Chrome会从谷歌开关:https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc
和彼得CHROM名单开关:https://开头彼得.sh / experiments / chromium-command-line-switches
/

我含糊地尝试了chrome_options.add_argument(’-disable-useAutomationExtension’),但这也没有帮助。

因此,我需要您的指导和建议。请帮忙。

代码部分:

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()

编辑
:我也知道这个问题的官方谷歌答案,他们正在努力,它与devtools命令和东西有关。由于它永远需要我寻找任何临时的解决方案或建议。链接:https//bugs.chromium.org/p/chromedriver/issues/detail?id
= 639

关注者
0
被浏览
283
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    该驱动程序在Chrome中安装了扩展程序,以实现一些功能,例如截屏。

    可以通过以下useAutomationExtension选项禁用它:

    from selenium import webdriver
    
    capabilities = {
      'browserName': 'chrome',
      'chromeOptions':  {
        'useAutomationExtension': False,
        'forceDevToolsScreenshot': True,
        'args': ['--start-maximized', '--disable-infobars']
      }
    }
    
    driver = webdriver.Chrome(desired_capabilities=capabilities)
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看