Alert not detected by webdriver function

684 views
Skip to first unread message

Deepa C

unread,
Jun 18, 2013, 8:17:51 PM6/18/13
to seleniu...@googlegroups.com
Hi , 
1.  I am testing a form which creates new users. After saving all the details , alert appears with the message that "user xyz is created". 
I have following method in my junit code.  This method is called to check if alert  popped up. 

  public void checkAlert() {
   try {
    Alert alert = driver.switchTo().alert();
       WebDriverWait wait = new WebDriverWait(driver, 1);
       wait.until(ExpectedConditions.alertIsPresent());        
       System.out.println("checkAlert method- Alert is present");
       alert.accept();
   } catch (Exception e) {
       //exception handling
    System.out.println("checkAlert method- Alert is NOT present");
   }
}
  
2. When I run my junit code, I see that alert pops up . But console shows  message "checkAlert method- Alert is NOT present"

3. I need to detect this alert and grab its text for further testing. 

Can anyone please let me know why this Alert is not detected by the code ?
FYI .. Developer is using jquery colorbox to generate this alert. 
I am using selenium-2.33.0 and running my test on Firefox.

Thanks 
 

Krishnan Mahadevan

unread,
Jun 19, 2013, 1:16:58 AM6/19/13
to Selenium Users
You would need to share the html source of the section that generates the alert.

You are gobbling up the Exception and printing the message.

Perhaps you might want to add e.printStackTrace() to get a better understanding as to what caused the Exception to be raised.

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/


 

--
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/c5a2f0b3-d6ec-4bf5-9dd0-344fe0479fa5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Divya Maheshwari

unread,
Jun 19, 2013, 7:32:57 AM6/19/13
to seleniu...@googlegroups.com
Hi,

I was also facing the same problem you have to put some extra sleep / wait for element for that alert to come properly. it will resolve your issue

Thanks

Manoj Hans

unread,
Jun 19, 2013, 7:51:21 AM6/19/13
to seleniu...@googlegroups.com
try with direct cmd  driver.switchTo().alert().accept(); instead of method and let us know that alert handle or not.
As per my assumption system throwing null pointer exception for better understanding do as krishnan suggested.


--Manoj Hans

Mark Collin

unread,
Jun 19, 2013, 7:52:29 AM6/19/13
to seleniu...@googlegroups.com
Putting in sleeps is absolutely the wrong thing to do and, since there is an explicit wait there, totally pointless.

My first question is are you really waiting for an alert or is it a lightbox (I've seen some lightboxes that have been styled to look like alert boxes)?
--
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.
Message has been deleted

Deepa C

unread,
Jun 19, 2013, 2:47:02 PM6/19/13
to seleniu...@googlegroups.com
Stacktrace produced following:

org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.10 seconds
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_21'
Session ID: 277887e1-9146-4d99-b1c1-5b368a9619ff
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=21.0}]

Krishnan Mahadevan

unread,
Jun 19, 2013, 2:48:43 PM6/19/13
to seleniu...@googlegroups.com
So that kind of confirms what Mark stated. Your alert might not be an actual alert afterall and instead just be a lightbox of instead. 
--
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/f6763ab5-2603-43d7-bc22-47410b5b3bc5%40googlegroups.com.

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


--

Deepa C

unread,
Jun 19, 2013, 3:05:04 PM6/19/13
to seleniu...@googlegroups.com
Thank you Mark & everyone .  Developer is using jquery plugin colorbox. 
So you are right. This is not a real alert. 
I called check_pop_up() method and it works fine.
When there is popup it says - "the colorbox pop up is displayed ?  True"
When there is NO popup it says - "the colorbox pop up is displayed ?  False"

  public void check_pop_up() {
 
 try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
 
    System.out.println("the colorbox pop up is displayed ? " +   driver.findElement(By.id("colorbox")).isDisplayed() );
 
  }

Thanks 
Deepa

On Tuesday, June 18, 2013 5:17:51 PM UTC-7, Deepa C wrote:
Reply all
Reply to author
Forward
0 new messages