Closed gogonutsss closed 2 years ago
@gogonutsss, thank you for creating this issue. We will troubleshoot it as soon as we can.
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template
label.
If the issue is a question, add the I-question
label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted
label.
After troubleshooting the issue, please add the R-awaiting answer
label.
Thank you!
You can add Authentication Handler
var handler = new NetworkAuthenticationHandler()
{
UriMatcher = _ => true,
Credentials = new PasswordCredentials(username, password)
};
driver.Manage().Network.AddAuthenticationHandler(handler);
This is C# code, but I think there are analogs in java.
Thanks for this, I dont see something relevant to this in https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.Options.html
With Selenium 4, you can use basic auth for this, please check https://www.selenium.dev/documentation/webdriver/bidi_apis/#register-basic-auth
Thanks a lot for the response.
I tried using BIDI and proxy setting, code being like below:
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/pathTo/chromedriver");
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setSocksUsername("myProxyUsername");
proxy.setSocksPassword("myProxyPassword");
proxy.setSslProxy("corporateProxy:port");
options.setCapability("proxy", proxy);
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);
try {
Predicate<URI> uriPredicate = uri -> uri.getHost().contains("https://urlIamTryingToAccess");
((HasAuthentication) driver).register(uriPredicate,
UsernameAndPassword.of("myProxyUsername", "myProxyPassword"));
driver.get("https://urlIamTryingToAccess");
driver.findElement(By.name("username")).sendKeys("aUsername");
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}
Response is a 407 Proxy authentication error:
Tried also, without setting at all Proxy object as a capability, just by using the bidi approach:
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/pathTo/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);
try {
Predicate<URI> uriPredicate = uri -> uri.getHost().contains("https://urlIamTryingToAccess");
((HasAuthentication) driver).register(uriPredicate,
UsernameAndPassword.of("myProxyUsername", "myProxyPassword"));
driver.get("https://urlIamTryingToAccess");
driver.findElement(By.name("username")).sendKeys("aUsername");
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}
In this case, I ended up with something very odd, I do get to see that driver.get is executed, and I get back an status code OK 200, but just a blank screen, nothing actually loaded and code is ready to go to the next command.
Why are you trying to send driver.findElement(By.name("username")).sendKeys("aUsername");
? You should be already logged in.
If you have any questions or need help, join us in the IRC/Slack channel where the community can help you as well.
The final part where I try to find elements to type agaist assumes the page of the application has really loaded - assumes I have passed the corporate proxy - and so I should be in a position to try to login to the application itself with my credentials (in other words this is the real test part). Thanks for checking and pointing for the slack channel too.
RemoteWebDriver not work! class cast exception
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
What happened?
I try to access a url that needs a corporate proxy with authentication in order to be accessed. Chrome seems to go through proxy, but I get the authentication prompt to input the credentials, that I would expect to be automatically set programmatically via my Proxy object:
See more on the simple example below. Code obviously fails on line 27 as it tries to find an element but actually what I have is the prompt on the sceen above.
How can we reproduce the issue?
Relevant log output
Operating System
Ubuntu 18
Selenium version
Java 4.0.0
What are the browser(s) and version(s) where you see this issue?
Chrome 95.0.4638.69
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 95.0.4638.69
Are you using Selenium Grid?
nope