Python selenium Chrome正在受到自动软件的控制 disable-infobars无效 的解决方法
2024-08-23 10:17:11
问题解决
前两天更新了google浏览器版本,今天运行以前的脚本,发现options一个参数的配置不生效了。
运行了几次都发现该参数没有生效,也检查了自己的代码参数,没有写错,于是就有了这一波“网中寻求答案”的操作。
苦寻不易,还真就找到了答案,详细可参见该地址的答案:https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification,里面有详细解答。
我也针对自己的代码进行了修改,也已生效。代码修改如下:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
driver = webdriver.Chrome(options=chrome_options)
老版本浏览器的写法还是如下所示代码:
chrome_options.add_argument('--disable-infobars') # 不显示正在受自动化软件控制
java代码修改如下:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(caps);
options参数
统计了一些常用参数,如下所示:
options.add_argument('--disable-infobars') # 禁止策略化
options.add_argument('--no-sandbox') # 解决DevToolsActivePort文件不存在的报错
options.add_argument('window-size=1920x3000') # 指定浏览器分辨率
options.add_argument('--disable-gpu') # 谷歌文档提到需要加上这个属性来规避bug
options.add_argument('--incognito') # 隐身模式(无痕模式)
options.add_argument('--disable-javascript') # 禁用javascript
options.add_argument('--start-maximized') # 最大化运行(全屏窗口),不设置,取元素会报错
options.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面
options.add_argument('blink-settings=imagesEnabled=false') # 不加载图片, 提升速度
options.add_argument('--headless') # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" # 手动指定使用的浏览器位置
options.add_argument('lang=en_US') # 设置语言
options.add_argument('User-Agent=Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36')
options.add_argument('--headless') # 浏览器不提供可视化页面
prefs = {"":""}
prefs["credentials_enable_service"] = False
prefs["profile.password_manager_enabled"] = False
chrome_option_set.add_experimental_option("prefs", prefs) # 屏蔽'保存密码'提示框
最新文章
- 游戏 gui button
- WebForm在JS中从Dropdownlist添加数据,在C#段读取
- Codeforces Round #250 (Div. 2)A(英语学习)
- Django: TemplateDoesNotExist at /admin/
- 【转】Maven实战(八)---模块划分
- oracle中的数据读取与查找
- Qt :非window子窗体的透明度设置
- iOS6与iOS7屏幕适配技巧
- Pyramid of Glasses(递推)
- FiddlerCoreAPI开发(一)源码分析
- .Net之路,感谢对我深远影响的三位前辈
- json中带有\r\n处理
- js生成1-100不重复的随机数及生成10个1-100不重复的随机数
- lua 函数基础
- hdu 5228 OO’s Sequence(单独取数算贡献)
- 基础邮件原理(MUA,MTA,MDA)
- vab set dim
- UVa 1637 纸牌游戏(全概率公式)
- Hadoop(12)-MapReduce框架原理-Hadoop序列化和源码追踪
- HDU 5952 [DFS]
热门文章
- 文件上传 Window &; Linux
- 5.Metasploit攻击载荷深入理解
- 玩转控件:封装Dev的SearchLookupEdit
- Kafka监控:主要性能指标
- 关于C#三层架构中的“分页”功能
- Go语言笔记 (2) 变量命名与多重赋值
- iOS, Xcode11,项目提示第三方库报错无法运行 bundle format unrecognized, invalid, or unsuitable
- WireShark数据包分析一:认识WireShark
- Python zipfile模块学习
- 数据库里账号的密码,需要怎样安全的存放?—— 密码哈希(Password Hash)