selenium加载配置参数,让chrome浏览器不出现‘Chrome正在受到自动软件的控制’的提示语,以及后台静默模式运行,不占用桌面的方法
一:自动化测试的时候,启动浏览器出现‘Chrome正在受到自动软件的控制’,怎么样隐藏,今天学习分享:
在浏览器配置里加个参数,忽略掉这个警告提示语,disable_infobars
option = webdriver.ChromeOptions()
参考代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import re from selenium import webdriver import time from selenium.webdriver.common.by import By # 加启动配置 option = webdriver.ChromeOptions() option.add_experimental_option( 'useAutomationExtension' , False) option.add_experimental_option( "excludeSwitches" , [ 'enable-automation' ]) option.add_argument( '--start-maximized' ) def startUp(): driver = webdriver.Chrome(options=option) driver.maximize_window() driver.get( "https://www.baidu.com" ) driver.implicitly_wait(3) # driver.find_element(By.CSS_SELECTOR,'input[id="kw"]').send_keys('测试开发') # time.sleep(3) res = driver.find_element(By.XPATH, '//*[@id="hotsearch-content-wrapper"]' ).get_attribute( 'innerText' ) driver.implicitly_wait(3) print(res) res2 = driver.find_element(By.XPATH, '//*[@id="hotsearch-content-wrapper"]' ).get_attribute( 'innerHTML' ) print(res2) pattern = 'class="title-content-title">(.*?)</span>' result = re.findall(pattern, res2) print(result) driver.get_screenshot_as_file(r 'C:\Users\jingwenshuai\Desktop\code\framework\seleniumWeb\a.png' ) driver.quit() if __name__ == '__main__' : startUp() |
还有可能是你的Chrome浏览器和驱动不匹配
chrome和驱动对应版本号可以查看链接:https://blog.csdn.net/huilan_same/article/details/51896672
由于笔者的版本是67.0,所以应该下的驱动是V2.40
下载的地址为:http://npm.taobao.org/mirrors/chromedriver/ 或者http://chromedriver.storage.googleapis.com/index.html
也可参考这篇:https://blog.csdn.net/weixin_44318830/article/details/103339273
本文作者:香菜哥哥
本文链接:https://www.cnblogs.com/yizhipanghu/p/9485382.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY