0

Scenario: selenium, java, firefox and alerts So, I wrote some time back code to deal with an alert while crawling websites.

This sort of code is easily found when searching for selenium and alerts ..

    try {
        Alert alert = driver.switchTo().alert();
        alert.accept();
    } catch (NoAlertPresentException e) {
        LOGGER.debug("No alert available: " + url);
    }

This seemed to work for the a couple test cases I had. One is the tomcat home page, on it you get a popup if you click 'status' for example.

Now I bumped into a dialog that blocks the above code. the switchTo() returns a TargetLocator but alert() on that locator blocks and never returns.

The links that triggers that dialog is http://www.fcb.com/news/rss.

Also, on this post I found a comment saying "we can't get a handle on confirmation boxes that are created on the onload functions" I wonder what that means but my reputation is so low I can't comment yet :).

Also, as pointed out in the first answer, both the problematic dialog and the one that works are "authentication" alerts. I don't want to authenticate.

So, to recap, the ask is why does the TargetLocator.alert() call block? My ultimate goal is to close any such dialog I may encounter after driver.get(url).

Any thoughts?

Thanks Cristian

p.s. regarding the duplicate tag, I don't think it's a duplicate. The code suggested there does not work either. One of the main objectives for my question is to understand why this popup blocks on the call to alert()

Community
  • 1
  • 1
Cristian
  • 91
  • 10
  • you can use alert for confirmation windows.... – Helping Hands May 06 '15 at 02:51
  • possible duplicate of [How to handle authentication popup with Selenium Webdriver](http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver) – Louis May 06 '15 at 16:24

1 Answers1

0

As per link you provided http://www.fcb.com/news/rss, on navigating to this, it displaying authentication popup. its not alerts that's the reason you are facing issue..

check this:Handling Browser Authentication using Selenium

if it not what you looking for, please explain the issue as i am not able to comment to get more explanation.

Thank you, Murali

Community
  • 1
  • 1
murali selenium
  • 3,847
  • 2
  • 11
  • 20
  • Right, it's an authentication pop-up. But I thought it would be detected as an "alert". I don'y care about authenticating on that page. I just want to close it, get over it. The link referred by you also calls such a dialog an alert. – Cristian May 06 '15 at 14:14
  • @Cristian the HTTP authentication popup cannot be directly manipulated with selenium, it is not an alert in selenium terms. – alecxe May 06 '15 at 15:00
  • @Cristian: Then you can use keyevents in selenium or Robot class in Java to simulate escape to avoid that authentication popup. i am expecting by escape that popup will disappear if not use appropriate keys.. – murali selenium May 06 '15 at 16:13
  • @alecxe: But another authentication popup, very similar in terms of looks at least is detected by Selenium as alert. I am talking about the manager of tomcat for example. On a default installation of tomcat, if u try localhost:8080/manager u get authentication popup. Selenium detects it as alert. Also, this SO link (http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver) speaks about handling auth popups with Selenium and the code has an alert in it – Cristian May 06 '15 at 17:59
  • @muraliseleniumtrainer, thanks, I may have to try Robot or maybe Autoit. I just wanted to understand the difference between the 2 similiar authentication pop-ups: the one detected as alert and the one from fcb that hangs on the call I mentioned – Cristian May 06 '15 at 18:10