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

Posted 安琪儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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


 

 

实现结果:

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

 

以上是关于Python_Selenium之浏览器封装_去掉浏览器受到自动化控制横条显示及去掉是否记住密码弹窗的主要内容,如果未能解决你的问题,请参考以下文章

python_selenium 之yaml文件读取(以读取元素信息为例)

python_selenium 之yaml文件读取(以读取元素信息为例)

python_selenium元素定位_xpath

Python_Selenium操作Firefox浏览器

python_selenium简单记录一下

python_selenium简单记录一下