搜索了一段时间后,尝试了所有存在的解决方案,但似乎都没有用。我创建了一个“幻灯片放映”,它将首先登录,然后在选项卡之间交替。所有这些都有效,但是我无法摆脱
“ Chrome正在由自动测试软件控制”栏。有什么建议吗?
代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'test'
passwordStr = 'test'
browser = webdriver.Chrome()
#first tab
browser.get(('www.testwebsite.com?'))
# fill in username and hit the next button
username = browser.find_element_by_id('username')
username.send_keys(usernameStr)
password = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, 'password')))
password.send_keys(passwordStr)
nextButton = browser.find_element_by_class_name('emp-submit')
nextButton.click()
#second tab
browser.execute_script("window.open('about:blank', 'tab2');")
browser.switch_to.window("tab2")
browser.get('www.testwebsite.com')
答案 0 :(得分:0)
当您通过 ChromeDriver 打开 Chrome浏览器时,该包含 notification 的信息栏将如下嵌入:
Chrome is being controlled by automated test software
disable-infobars
的浏览器快照:但是,如果您通过 ChromeOptions 的实例添加参数 disable-infobars ,则可以按以下方式删除此信息栏:
代码块:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.google.com/')
应用参数disable-infobars
的浏览器快照:
答案 1 :(得分:0)
尝试一下:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_path = '/Users/myuser/Downloads/chromedriver'
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
driver.get('https://google.com')
driver.close()