有没有办法使用 Selenium WebDriver 而不通知文档它是由 WebDriver 控制的?

我正在自动化一个调用 CAPTCHA 来验证登录的网页,但我注意到这个页面只在我使用我的自动化测试代码时才请求这个 CAPTCHA,当我手动执行它时它不会请求.我要求开发团队在 QA 环境中禁用它,但通过安全代码无法实现.

I'm automating an Web page who call a CAPTCHA to validate the login, but I noticed that this page only request this CAPTCHA when I'm using my automatized test code, when I do it manually it don't request. I asked to developer team to disable it on the QA environment, but it's not possible by a security code.

我需要知道是否有办法不告诉浏览器我正在此页面上使用自动化测试.

I need to know if there is a way to don't say to browser that I'm using automated test on this page.

你能帮帮我吗?

推荐答案

不行,没有办法隐瞒你正在运行自动化测试.

No, there is no way to conceal that you are runing automated test.

当使用 WebDriver 接口时,webdriver-active 标志 设置为 true,因为用户代理处于远程控制之下.它最初是错误的.

When using the WebDriver interface the webdriver-active flag is set to true as the user agent is under remote control. It is initially false.

WebIDL

Navigator includes NavigatorAutomationInformation;

请注意,NavigatorAutomationInformation 接口不应暴露在 WorkerNavigator 上.

Note that the NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.

WebIDL

interface mixin NavigatorAutomationInformation {
    readonly attribute boolean webdriver;
};

网络驱动程序

  • 如果设置了 webdriver-active 标志,则返回 true,否则返回 false.

例子

  • 对于网络作者:

  • For web authors :

navigator.webdriver

Defines a standard way for co-operating user agents to inform the document that it is controlled by WebDriver, for example so that alternate code paths can be triggered during automation.

上述实现基于几个安全注意事项如下:

The above mentioned implementation is based on a couple of Security Considerations as follows:

  • 用户代理可以依靠命令行标志或配置选项来测试是否启用 WebDriver,或者让用户代理通过特权内容文档或控制小部件启动或确认连接,以防万一用户代理不直接实现 HTTP 端点.

  • A user agent can rely on a command-line flag or a configuration option to test whether to enable WebDriver, or alternatively make the user agent initiate or confirm the connection through a privileged content document or control widget, in case the user agent does not directly implement the HTTP endpoints.

强烈建议用户代理要求用户采取明确的操作来启用 WebDriver,并且 WebDriver 在用户代理的公开使用版本中保持禁用状态.

It is strongly suggested that user agents require users to take explicit action to enable WebDriver, and that WebDriver remains disabled in publicly consumed versions of the user agent.

还建议用户代理努力在视觉上将受 WebDriver 控制的用户代理会话与用于正常浏览会话的用户代理会话区分开来.这可以通过浏览器 chrome 元素来完成,例如 门衣架、操作系统窗口的彩色装饰或窗口中流行的一些小部件元素,以便于识别自动化窗口.p>

It is also suggested that user agents make an effort to visually distinguish a user agent session that is under control of WebDriver from those used for normal browsing sessions. This can be done through a browser chrome element such as a door hanger, colorful decoration of the OS window, or some widget element that is prevalent in the window so that it easy to identify automation windows.

您可以在以下位置找到一些详细的讨论:

You can find a couple of detailed discussion in:

  • Distil 检测 WebDriver 驱动的 Chrome 浏览上下文
  • Selenium webdriver:修改导航器.webdriver 标志以防止硒检测
  • Akamai Bot Manager 检测到 WebDriver 驱动的 Chrome 浏览上下文

相关文章