Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

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 Fri Apr 02, 2010 3:06 am

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-02

Back to top Go down

Re: Alert handling (Java)

Post by metman on Fri Apr 02, 2010 5:37 am

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-02

Back to top Go down

Re: Alert handling (Java)

Post by metman on Sat Apr 17, 2010 7:07 am

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-02

Back to top Go down

Re: Alert handling (Java)

Post by tejastrivedi on Sat Sep 17, 2011 12:26 am

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-02

Back to top Go down

Re: Alert handling (Java)

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

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 Today at 1:01 pm


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