Python_Selenium之浏览器封装_去掉浏览器受到自动化控制横条显示及去掉是否记住密码弹窗

封装如下:

from selenium import webdriver
from common.config_utils import config
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

def set_driver():
chrome_options = webdriver.ChromeOptions()
prefs = {"": ""}
prefs["credentials_enable_service"] = False
prefs["profile.password_manager_enabled"] = False
chrome_options.add_experimental_option("prefs", prefs) ##关掉密码弹窗
chrome_options.add_argument('--disable-gpu') # 谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('lang=zh_CN.UTF-8') # 设置默认编码为utf-8
chrome_options.add_experimental_option('useAutomationExtension', False) # 取消chrome受自动控制提示
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) # 取消chrome受自动控制提示

driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
return driver


 

 

实现结果:

没有了受到自动化控制的横条显示,也没有了记住密码的弹窗。

 

posted @ 2020-05-04 12:17  安琪儿一直在  阅读(1438)  评论(0编辑  收藏  举报