2

I am trying to run selenium automation on a 3rd party website.

Selenium fails when firefox authentication prompt like this appears:

enter image description here

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

Liam Ferris
  • 1,786
  • 2
  • 18
  • 38
  • 3
    Possible duplicate of [How to handle authentication popup with Selenium WebDriver using Java](http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java) – optimistic_creeper Sep 30 '16 at 11:02
  • 1
    Did you try this format `http://username:password@URL.com` – Chandra Shekhar Sep 30 '16 at 13:05
  • @ChandraShekhar In our scenario we don't actually want to authenticate. We just want to dismiss the prompt, the issue is we are unable to query when the prompt appears – Liam Ferris Sep 30 '16 at 13:11
  • Can you please provide any alternate link which will pop up the same way? [To check for solution] – Chandra Shekhar Sep 30 '16 at 13:20
  • http://www.httpwatch.com/httpgallery/authentication/#showExample10 The display image button, added it to the question too :) – Liam Ferris Sep 30 '16 at 13:21

1 Answers1

1

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();
Chandra Shekhar
  • 664
  • 2
  • 9
  • 24