在我的 Selenium-Test
(使用 chromedriver-2.24
)中,我尝试使用以下语句通过基本身份验证访问我的网页:
WebDriver driver = ...;
driver.get("http://admin:admin@localhost:8080/project/");
但是 Google Chrome 在控制台中向我发出以下警告:
[Deprecation] Subresource requests whose URLs contain embedded credentials (e.g.
https://user:pass@host/
) are blocked. See https://www.chromestatus.com/feature/5669008342777856 for more details.
在标记的链接中提到支持已被删除:
Drop support for embedded credentials in subresource requests. (removed)
我现在的问题是,是否还有其他方法可以从 Selenium 进行基本身份验证?
注意:这没有帮助:How to Handle HTTP Basic Auth headers in Selenium Webdriver using Java ?
最佳答案
仅针对子资源阻止通过 url 进行的基本身份验证。 因此您仍然可以在域上使用它:
driver.get("http://admin:admin@localhost:8080");
driver.get("http://localhost:8080/project");
您还可以创建一个小型扩展程序,以便在请求时自动设置凭据:
options = webdriver.ChromeOptions()
options.add_extension(r'C:\dev\credentials.zip')
https://gist.github.com/florentbr/25246cd9337cebc07e2bbb0b9bf0de46
关于java - Selenium - 通过 url 进行基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57161680/