问题解决

前两天更新了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) # 屏蔽'保存密码'提示框

最新文章

  1. 游戏 gui button
  2. WebForm在JS中从Dropdownlist添加数据,在C#段读取
  3. Codeforces Round #250 (Div. 2)A(英语学习)
  4. Django: TemplateDoesNotExist at /admin/
  5. 【转】Maven实战(八)---模块划分
  6. oracle中的数据读取与查找
  7. Qt :非window子窗体的透明度设置
  8. iOS6与iOS7屏幕适配技巧
  9. Pyramid of Glasses(递推)
  10. FiddlerCoreAPI开发(一)源码分析
  11. .Net之路,感谢对我深远影响的三位前辈
  12. json中带有\r\n处理
  13. js生成1-100不重复的随机数及生成10个1-100不重复的随机数
  14. lua 函数基础
  15. hdu 5228 OO’s Sequence(单独取数算贡献)
  16. 基础邮件原理(MUA,MTA,MDA)
  17. vab set dim
  18. UVa 1637 纸牌游戏(全概率公式)
  19. Hadoop(12)-MapReduce框架原理-Hadoop序列化和源码追踪
  20. HDU 5952 [DFS]

热门文章

  1. 文件上传 Window & Linux
  2. 5.Metasploit攻击载荷深入理解
  3. 玩转控件:封装Dev的SearchLookupEdit
  4. Kafka监控:主要性能指标
  5. 关于C#三层架构中的“分页”功能
  6. Go语言笔记 (2) 变量命名与多重赋值
  7. iOS, Xcode11,项目提示第三方库报错无法运行 bundle format unrecognized, invalid, or unsuitable
  8. WireShark数据包分析一:认识WireShark
  9. Python zipfile模块学习
  10. 数据库里账号的密码,需要怎样安全的存放?—— 密码哈希(Password Hash)