selenium 选项 chrome_options

当前环境:

Windows 10 + Python 3.7 + selenium 3.141.0 + Google Chrome 115.0.5790.110 (64 位)

一种方法:

python 复制代码
from selenium import webdriver


if __name__ == '__main__':
    # chrome 选项配置
    chrome_options = webdriver.ChromeOptions()
    # 设置无界面浏览
    # chrome_options.add_argument('--headless')
    # 忽略证书报错
    chrome_options.add_argument('ignore-certificate-errors')
    # 取消chrome受自动控制提示
    chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 关掉密码弹窗
    prefs = {"": "", "credentials_enable_service": False, "profile.password_manager_enabled": False}
    chrome_options.add_experimental_option("prefs", prefs)
    # Chrome.exe 路径
    chrome_options.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    # chromedriver.exe 路径
    ChromedriverPath = r'.\chromedriver.exe'
    driver = webdriver.Chrome(ChromedriverPath, options=chrome_options)

    # 打开百度
    driver.get('https://www.baidu.com')

另外一种方法:

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


if __name__ == '__main__':
    # chrome 选项配置
    options = Options()
    # 设置无界面浏览
    # options.add_argument('--headless')
    # 忽略证书报错
    options.add_argument('ignore-certificate-errors')
    # 取消chrome受自动控制提示
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 关掉密码弹窗
    prefs = {"": "", "credentials_enable_service": False, "profile.password_manager_enabled": False}
    options.add_experimental_option("prefs", prefs)
    # Chrome.exe 路径
    options.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    # chromedriver.exe 路径
    ChromedriverPath = r'.\chromedriver.exe'
    driver = webdriver.Chrome(ChromedriverPath, options=options)

    # 打开百度
    driver.get('https://www.baidu.com')

参考:

selenium关闭左上方Chrome 正受到自动测试软件的控制的提示 - 简书

https://www.cnblogs.com/yangjintao/p/10599868.html

相关推荐
典学长编程2 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
百锦再8 小时前
.Net配置文件appsetting.json的几种读取方法
chrome·json·.net·依赖注入·appsetting·web.config
大猫会长12 小时前
mac中创建 .command 文件,执行node服务
前端·chrome
巴里巴气14 小时前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
未来之窗软件服务16 小时前
chrome webdrive异常处理-session not created falled opening key——仙盟创梦IDE
前端·人工智能·chrome·仙盟创梦ide·东方仙盟·数据调式
2501_9240641117 小时前
2025年跨端云真机测试平台深度测评:XR与折叠屏时代的兼容性之战
测试工具·移动端自动化测试·自动化测试脚本
Small black human1 天前
HTTP-Postman的安装及其使用
测试工具·postman
涛哥码咖1 天前
chrome安装AXURE插件后无效
前端·chrome·axure
AIZHINAN1 天前
Appium 简介
自动化测试·测试工具·appium
吴free1 天前
mac电脑wireshark快速实现http接口抓包
网络·测试工具·http·wireshark