Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
metman
Amateur
Amateur
Posts : 58
Join date : 2010-04-02

Alert handling (Java) Empty Alert handling (Java)

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.
avatar
metman
Amateur
Amateur
Posts : 58
Join date : 2010-04-02

Alert handling (Java) Empty Re: Alert handling (Java)

Fri Apr 02, 2010 5:37 am
I'm looking at using:

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

Should that work correctly?
avatar
metman
Amateur
Amateur
Posts : 58
Join date : 2010-04-02

Alert handling (Java) Empty Re: Alert handling (Java)

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.
avatar
tejastrivedi
Posts : 3
Join date : 2011-09-02

Alert handling (Java) Empty Re: Alert handling (Java)

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
avatar
susmitha
Active particpant
Active particpant
Posts : 15
Join date : 2011-10-21

Alert handling (Java) Empty Re: Alert handling (Java)

Fri Oct 21, 2011 8:07 pm
try this
assertEquals("AlertMessage", selenium.getAlert());
Sponsored content

Alert handling (Java) Empty Re: Alert handling (Java)

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