Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Alert handling (Java)

View previous topic View next topic Go down

Alert handling (Java)

Post by metman on Thu Apr 01, 2010 3:06 pm

Hello, I've been working with Selenium in Java, and have come across a question for which the JavaDocs are wanting. For the getAlert() method, the docs say that if an alert is not detected, the method "fails". What is the failure behavior? Does it assert? Throw an exception? What?

I'm looking to write some code that enters data in to a form (credit card info), and on that form, if the user attempts to enter, for instance, characters in to the credit card number field, the page throws an Alert. As a means of illustration, let me give a snippet:

public void add(Selenium selenium) throws Exception {
(...)
selenium.type("creditCardNumber", cardNumber);
***need logic to handle possible Alert here**
throw new Exception(alertMessage);
(...)
}

The basic idea is that this method adds a credit card through a form, and I want it to bubble up any Alerts it generates through exceptions to the calling method. As mentioned, I think getAlert() is the way to go, but any further elaboration anyone could provide would be appreciated.

metman
Amateur
Amateur

Posts : 58
Join date : 2010-04-01

Back to top Go down

Re: Alert handling (Java)

Post by metman on Thu Apr 01, 2010 5:37 pm

I'm looking at using:

if (selenium.isAlertPresent()) {
throw new Exception(selenium.getAlert());
}

Should that work correctly?

metman
Amateur
Amateur

Posts : 58
Join date : 2010-04-01

Back to top Go down

Re: Alert handling (Java)

Post by metman on Fri Apr 16, 2010 7:07 pm

Should anyone come across this thread with a similar problem, yes, this works. The only thing for me was I had to use the selenium.typeKeys() method as opposed to selenium.type() because the alert box was triggered by keyUp events.

metman
Amateur
Amateur

Posts : 58
Join date : 2010-04-01

Back to top Go down

Re: Alert handling (Java)

Post by tejastrivedi on Fri Sep 16, 2011 12:26 pm

hi all in my application i have alert message on page load. i want to handle ok button click automatiocally pls guide

tejastrivedi

Posts : 3
Join date : 2011-09-01

Back to top Go down

Re: Alert handling (Java)

Post by susmitha on Fri Oct 21, 2011 8:07 am

try this
assertEquals("AlertMessage", selenium.getAlert());

susmitha
Active particpant
Active particpant

Posts : 15
Join date : 2011-10-21

Back to top Go down

Re: Alert handling (Java)

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum