我想從我的辦公室環境中運行一個基本的硒腳本,它有一個代理和防火牆設置。該腳本運行正常,除非在每次執行之前它會彈出一個消息:「加載解壓後的擴展名被管理員禁用」。這意味着我將不得不手動點擊它繼續進行,這違背了自動化的目的。 什麼是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
工作就像一個魅力。感謝一羣@Florent B. 對於那些將來會看到這個問題並嘗試使用我們上面共享的代碼的人,請將我的代碼的所有chrome_options行+帶有self.driver的第一行替換爲Florent的代碼。它會工作。 – S4nd33p