selenium官方中文文档_【自动化】Selenium如何隐藏“Chrome is being controlled...”

Selenium隐藏“Chrome is being controlled by automated test software”并附上最新chromedriver options&Capabilities

使用Selenium的时候,想必大家都见过“Chrome is being controlled by automated test software”这个提示,那么怎么取消这个提示呢?取消这个提示之后会不会出现别的新的提示或者弹窗呢?

今天我们主要来探讨这个问题,关于这个问题,我先列出一个提纲:

  1. 首先,如何隐藏“Chrome is being controlled by automated test software”?
  2. 隐藏之后如何隐藏“disable developer mode extensions”?
  3. 又如何隐藏“Save password”弹窗?

开始之前,我想要吐槽一下,我呢,平常工作多用SpringBoot和NodeJS,这会用Selenium主要是有个新的活需要用Selenium作为其中一步的解决方案,要求是坐标一定精准。

坐标精准就要求Selenium启动Chrome之后不能有多余的提示和弹窗,但是,这刚开始跑,就碰到“Chrome is being controlled by automated test software”这个提示了,我本以为这是个非常非常普遍且简单的问题,但是没想到,我错了。

我要声明一下,这个问题确实很普遍,而且最后解决方案也确实很简单,但是为什么我说我错了,是因为我在解决过程中着实是被咱们国内的某论坛,某博客,还有某某某恶心到了,通篇的粘贴复制,一字不改,有些格式估计亲妈都不认识,更别说为结果负责了,我真是我的心啊,拔凉拔凉的。

我还得说明一下,这个搜索结果还是我用Chrome搜索出来的中文结果,我都不敢想象如果我用某度搜索的话,估计我陷进去两天都没有进展。

好吧,言归正传吧,开始解决问题。

如何隐藏“Chrome is being controlled by automated test software”?

v2-942ecb2b75a8c75d2ea774128cef8a6c_b.png

我的环境如下:

// chrome://version
Google Chrome   78.0.3904.70 (Official Build) (64-bit) (cohort: 78_70_Win)
// Selenium version
3.14.0
// chromedriver version (using command: "chromedriver.exe --version")
ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800})

另外,请务必保证你的Chrome版本和chromedriver版本是匹配的,这是Google官方给出的建议,我引用如下:

We maintain multiple versions of ChromeDriver. Which version to select depends on the version of Chrome you are using it with. Specifically:
ChromeDriver uses the same version number scheme as Chrome. See https://www. chromium.org/developers /version-numbers for more details.
Each version of ChromeDriver supports Chrome with matching major, minor, and build version numbers. For example, ChromeDriver 73.0.3683.20 supports all Chrome versions that start with 73.0.3683.
Before a new major version of Chrome goes to Beta, a matching version of ChromeDriver will be released.
After the initial release of a new major version, we will release patches as needed. These patches may or may not coincide with updates to Chrome.

好了,回到题目,如果你去查了别的答案了,相信你得到的解决方法肯定是这样的:

# 这是错误示例,高版本Chrome请不要使用这个方法:

这个argument其实很早就已经被弃用了,你在Chrome 78版本上,用这个是不能解决问题的,但是呢,你去看看,某博客上2019年的博文都还是同样的解决方案,而且明显粘贴复制早年别人的答案,真是令人火大!

那么其实应该怎么解决呢,如下:

# Chrome 78 with Chromedriver 78 Works fine!

这里我想说一下,Chromedriver更新换代非常快,Options&Capabilities改动也特别快,所以有可能我给出的答案在一年之后可能也就成为历史了,因此我会特别标注我的实验环境以及当前实验环境下的实验结果。

我会在文章最后附上如何查询最新的Options&Capabilities,授人以鱼不如授人以渔,将来如果有变动了,大家也可以通过Google官方文档来获取最新的改动。

还有就是如果大家经常用ChromeDriver,可以多关注每个版本的release notes,比如说79版本:

v2-71ae0b61f96e27e1cadf117c57627090_b.jpg

移除了对“--ignore-certificate-errors”的支持,所以如果大家的代码中有这个,可以尽快寻找代替方案了!

OK,在移除了“Chrome is being controlled by automated test software”提示之后,你会发现多了两个弹窗,分别是:

v2-79a551ac32cbac4a35d10b1520b26276_b.jpg

v2-bcbb009d77d3a844d9ab30df90c72ecb_b.jpg

那么如何解决呢?

隐藏“disable developer mode extensions”

直接上代码吧:

options

这里要注意,不能使用“--disable-extations”参数,不起作用,具体原因还没有查明,猜测两种原因,一是有可能已经弃用了,二是有可能和“enable-automation”冲突了,如果有人知道,也可以给我说下。

隐藏“Save password”弹窗

options

最后,相关资料地址如下:

  1. Chromedriver版本对应关系及下载: https://chromedriver.chromium.org/downloads
  2. 老版本Chromedriver汇总下载: https://chromedriver.storage.googleapis.com/index.html
  3. Capabilities&ChromeOptions: https://sites.google.com/a/chromium.org/chromedriver/capabilities
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值