1

我想从我的办公室环境中运行一个基本的硒脚本,它有一个代理和防火墙设置。该脚本运行正常,除非在每次执行之前它会弹出一个消息:“加载解压后的扩展名被管理员禁用”。这意味着我将不得不手动点击它继续进行,这违背了自动化的目的。 enter image description here什么是Python的useAutomationExtension for selenium的等价物?

我GOOGLE和stackoverflowed错误,看起来像有一个铬选项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://peter.sh/experiments/chromium-command-line-switches/

我隐约试图chrome_options.add_argument(“ - 禁用 - useAutomationExtension”),但没”也没有帮助。

所以,我需要你的指导和建议。请帮忙。

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

编辑: 我也知道谷歌官方的回答这个问题,他们正在做这个工作,它有事情做与devtools命令和东西。因为这是永远的,我正在寻找任何临时解决方案或建议。链接:https://bugs.chromium.org/p/chromedriver/issues/detail?id=639

回答

2

该驱动程序在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) 
+0

工作就像一个魅力。感谢一群@Florent B. 对于那些将来会看到这个问题并尝试使用我们上面共享的代码的人,请将我的代码的所有chrome_options行+带有self.driver的第一行替换为Florent的代码。它会工作。 – S4nd33p

相关问题