SafariDriver says there's an alert, but there is not.

276 views
Skip to first unread message

Jeff

unread,
Oct 17, 2014, 9:53:50 PM10/17/14
to seleniu...@googlegroups.com
Safari 5.1.7 for windows
Windows 7 Ent x64 sp1
Selenium Java 2.43.1

Initially I ran my login test that enters bad user information and saw the UnhandledAlertException and found the Issue describing this problem and that it automatically dismisses the alert, so I disabled that test case.

I'm now trying the test case that enters only valid credentials and as far as I know, it doesn't generate an alert.  (I see nothing I need to dismiss)

If I use Selenium to fill in the information and click submit, the UnhandledAlertException is thrown as soon as I click on the Submit button even with valid credentials.

However, if I use Safari manually, I don't see any alerts and I get logged in just fine.  

Thoughts as to why this might be failing?  Or where to look for a potential issue?

Regards!

--
Jeff Vincent
See my LinkedIn profile at:
http://www.linkedin.com/in/rjeffreyvincent

Jeff

unread,
Oct 20, 2014, 4:46:54 PM10/20/14
to seleniu...@googlegroups.com

On Fri, Oct 17, 2014 at 7:53 PM, Jeff <preda...@gmail.com> wrote:

Regards!

Anyone have thoughts on this?

Janesh Kodikara

unread,
Oct 21, 2014, 11:44:25 AM10/21/14
to seleniu...@googlegroups.com
Hello Jeff,

1. Lets find the details of the alert if there is any 
    Following code will help you to write the alert message to the console and close it 
     Alert alert = webDriver.switchTo().alert();
     String alertMessage = alert.getText();
     System.out.println("Alert Message " + alertMessage);
     alert.accept();
        

2. You cannot see Alerts when Selenium code is executed (if any).

Following is extract from documentation 
"Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog."


Jeff

unread,
Oct 24, 2014, 4:33:25 PM10/24/14
to seleniu...@googlegroups.com
The problem comes with the SAFARI browser that doesn't handle alerts.  In my case it is a LOGIN page.  I enter the username and password, and as soon as I execute submit.click(), I get an UnhandledAlertException.  The Submit button never gets clicked.  There is no alert window open.  

So, I added an Alert check (below) before calling click(), but I get the following NoAlertPresentException:

The SafariDriver does not support alert handling. To prevent tests from handing when an alert is opened, they are always immediately dismissed. For more information, see http://code.google.com/p/selenium/issues/detail?id=3862 (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 19 milliseconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'PBTALYY-1', ip: '10.130.0.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: null
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{platform=WINDOWS, cssSelectorsEnabled=true, javascriptEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=5.1.7}]

Then on the very next call to click(), I get this UnhandledAlertException:

A modal dialog was opened. The SafariDriver does not support interacting with modal dialogs. To avoid hanging your test, the alert has been dismissed. For more information, see http://code.google.com/p/selenium/issues/detail?id=3862: Please enter your username
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'PBTALYY-1', ip: '10.130.0.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: null
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{platform=WINDOWS, cssSelectorsEnabled=true, javascriptEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=5.1.7}]

Here is the whole method:

public void login(String username, String password) {
        username_input.clear();
        username_input.sendKeys(username);
        password_input.clear();
        password_input.sendKeys(password);

        try {
            Alert alert = sb.driver.switchTo().alert();  //THROWS NoAlertPresentException
            String alertMessage = alert.getText();
            System.out.println("Alert Message " + alertMessage);
            alert.accept();
        } catch (Exception ex) {
            String msg = ex.getMessage();
            System.out.println(msg);
        }

        try {
            submit.click();   //THROWS UnhandledAlertException
        } catch (Exception ex) {
            String msg = ex.getMessage();
            System.out.println(msg);
        }
    }

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fa1543ee-6e11-4167-8a26-3fae31219722%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff

unread,
Oct 27, 2014, 10:37:14 PM10/27/14
to seleniu...@googlegroups.com
Anyone know if this is a bug or am I missing something?

Xiang Dong

unread,
Oct 27, 2014, 11:07:49 PM10/27/14
to seleniu...@googlegroups.com
I got similar problem before, looks like safari driver has some issues to handle alert dialog. It has a alert dialog, but in Safari browser test, we can't see it and accept/dismiss it. It is a safari legacy issue, you could inject some javascript to the web page and override javascript alert method. But it is of course not a good idea. If you find other solutions, pls tell me.

Best Regards,
--david


From: preda...@gmail.com
Date: Mon, 27 Oct 2014 20:35:46 -0600
Subject: Re: [selenium-users] Re: SafariDriver says there's an alert, but there is not.
To: seleniu...@googlegroups.com

Krishnan Mahadevan

unread,
Oct 28, 2014, 12:52:36 AM10/28/14
to Selenium Users
There is already a bug that is logged for this : https://code.google.com/p/selenium/issues/detail?id=3862

Please see if this is what you are after.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Jeff

unread,
Oct 28, 2014, 12:19:52 PM10/28/14
to seleniu...@googlegroups.com
That was the issue I referred to in my initial post.

However, none of the work-arounds allow me to get past this specific issue.  As I showed in the code snippet for the login process, I am trying to click the "Submit" button on a login screen.  The login screen will display an alert if invalid credentials are applied.

However, if i use VALID credentials (without webdriver), the login goes through and I see no alert dialogs.  If using webdriver/safaridriver, I get an exception that there is an unhandled alert and the Submit button does not get clicked.  If I check for an alert before clicking it says there is no alert.

I am unable to work around it and though it is related to alert handling, it doesn't appear to be an issue with handling an actual alert but seems that SafariDriver is incorrectly detecting the presence of an alert that does not exist. 

I suppose that there is a chance there is something in the web page content that is doing something that causes a faux alert, but not knowing what SafariDriver is doing, I don't know what to look for.

Should I open another issue or add detail to the existing issue?


For more options, visit https://groups.google.com/d/optout.

Always a student

unread,
Oct 5, 2017, 10:36:04 AM10/5/17
to Selenium Users
Jeff, were you able to find a solution. I am facing a similar issue with Firefox driver. 

Reply all
Reply to author
Forward
0 new messages