selenium: Chrome is controlled by automated test software

在 chrome v96 + selenium 4, 使用下面的 code 會顯示「Chrome is controlled by automated test software」

chrome_service = Service(chromedriver_path)
driver = webdriver.Chrome(desired_capabilities=caps, service=chrome_service)

改服用:

chrome_service = Service(chromedriver_path)
driver = webdriver.Chrome(options=chrome_options, service=chrome_service)

就解決了,示意圖:


This is because the browser is under Selenium’s control.


Solution

To get across this situation, we need to hide SeleniumChrome should not know that it is under control. To achieve that you need to add the following parameters through add_experimental_option() with in instance of Options() and pass it as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://www.google.com/")

Voila !!! now you will find the Google Chrome Browsing Context doesn’t contains the banner anymore.


資料來源

Automation in normal Google Chrome instance
https://stackoverflow.com/questions/70054770/automation-in-normal-google-chrome-instance

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *