Reputation: 1846
I am trying to run selenium automation on a 3rd party website.
Selenium fails when firefox authentication prompt like this appears:
Works like the Display Image button here
Is there any way to dismiss this using javascript, as part of a firefox extension or otherwise?
We have tried dismissing the prompt in selenium with the following:
Alert alert = driver.switchTo().alert();
alert.dismiss();
We have also tried disabling javascript although this solution doesn't work as we also require javascript to be enabled for our automation.
There seems to be a possible solution, as there is an extension that can handle this, we are unable to use this as we can't use 3rd party code and we would like slightly different behaviour.
Edit: different to linked question as we are looking for a in-browser solution using javascript
Any help or guidance is appreciated,
Liam
Upvotes: 2
Views: 922
Reputation: 664
I have tried with your inputs, Alert can be dismissed only after getting the alert text. Please try this working code
driver.get("http://www.httpwatch.com/httpgallery/authentication/#showExample10");
// open URL
driver.findElement(By.id("displayImage")).click();
Thread.sleep(2000);
driver.switchTo().alert();
Alert promptAlert = driver.switchTo().alert();
String alertText = promptAlert .getText();
System.out.println("Alert text is " + alertText);
promptAlert.dismiss();
Upvotes: 1