In my Selenium-Test
(with chromedriver-2.24
) I'm trying to access my webpage via basic authentication with the following statement:
WebDriver driver = ...;
driver.get("http://admin:admin@localhost:8080/project/");
But Google Chrome gives me the following warning in the console:
[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.
In the tagged link is mentioned that the support was dropped:
Drop support for embedded credentials in subresource requests. (removed)
My question now is, is there an other way to basic-authenticate from Selenium?
NOTE: this has not helped: How to Handle HTTP Basic Auth headers in Selenium Webdriver using Java ?
Selenium 4 supports basic authentication
WebDriver driver = new ChromeDriver();
HasAuthentication authentication = (HasAuthentication) driver;
authentication.register(() -> new UsernameAndPassword("username", "pwd"));
driver.get("your-site.com");
https://www.selenium.dev/blog/2021/a-tour-of-4-authentication/
The basic authentication via url is blocked only for sub resources. So you could still use it on the domain:
driver.get("http://admin:admin@localhost:8080");
driver.get("http://localhost:8080/project");
You could also create a small extension to automatically set the credentials when they are requested:
options = webdriver.ChromeOptions()
options.add_extension(r'C:\dev\credentials.zip')
https://gist.github.com/florentbr/25246cd9337cebc07e2bbb0b9bf0de46
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With