Aut*_*33k 5 authentication watir basic-authentication selenium-webdriver
我正在使用 watir(Ruby selenium 包)尝试使用基本身份验证登录到 url
我像这样传递凭据
https://username:password@nagios.com
Run Code Online (Sandbox Code Playgroud)
但是,当浏览器打开时,我会弹出一个窗口,要求再次输入凭据。
我使用的代码如下
driver = Watir::Browser.new :chrome
driver.goto "https://username:password@nagios.com"
Run Code Online (Sandbox Code Playgroud)
上面的代码打开浏览器 -> 转到 URL,但会弹出窗口以再次输入凭据。
如何使用基本身份验证登录该网址?
事实证明,Chrome 在版本 52 之后已停止支持在 url 中传递凭据。更多信息https://medium.com/@lmakarov/say-goodbye-to-urls-with-embedded-credentials-b051f6c7b6a3
要解决此问题,您需要 --disable-blink-features="BlockCredentialedSubresources"在启动浏览器时设置一个参数。它的作用是禁用该功能
这是我最终的有效代码
args = ['--disable-software-rasterizer',
'--disable-blink-features="BlockCredentialedSubresources"',
'--no-proxy-server',
'--disable-gpu',
'--no-sandbox',
'--ignore-certificate-errors']
driver = Watir::Browser.new :chrome, options: {args: args}
driver.goto "https://username:password@nagios.com"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18090 次 |
| 最近记录: |