In the Web application, there are several JavaScript alert messages appear while executing the scripts or simply operating the application. So we need to know that how to handle JavaScript Alert in Selenium Webdriver.
Let’s take a scenario to handle JavaScript Alert message
Scenario:
- Write a program to verify the JavaScript alert message for any validation of any overcount.
- Click on OK button of JavaScript alert message.
- Before clicking on Ok button, take the text message which is available in the alert message and print.
To handle the alert, we need to navigate from main window to alert. Then we can perform actions like either OK or Cancel.
Accept: It is to click OK on the alert message.
Dismiss: It is to click Cancel on the confirmation alert message.
Syntax:
driver.switchto().alert().accept(); // to click on OK button.
driver.switchto().alert().dismiss(); // to click on Cancel button.
Get Text: It is to take the text or label from the application where the webdriver is having the focus.
- The written type of get text is String.
Syntax:
string str;
str = driver.switchto().alert().gettext(); // to take the text message from the JavaScript alert
system.out.println(str); // to print the text message
Please click here to read Automation Script Implementation in Webdriver
Please click here to read Browser Launch in Selenium Webdriver
19 Comments
Chaithra
Nice Post.
Search Engine Optimization Training
Chaithra
Nice Post. Thank You For Sharing Looking for Some More Stuff.
Search Engine Optimization Training
Deepak
You have stated very simply that how to handle javascript alert in selenium
Nithi
The information you shared is very effective for learners.
Nadeem ogen
hello sir,
thanks for giving that type of information.
Smithk559
As a Newbie, I am continuously searching online for articles that can aid me. Thank you
saranya
Portal is a Web based portal brings Potentials Employers and Candidates on a common platform for placement assistance
Hairstyles
I simply couldn’t leave your website prior to suggesting that I extremely loved the usual info a person supply to your guests? Is going to be again regularly to inspect new posts
ayurvedu
Appreciate you sharing, great blog.Really thank you! Fantastic.
Short Hairstyles
Someone necessarily help to make severely posts I would state. This is the first time I frequented your web page and up to now? I amazed with the research you made to make this actual submit extraordinary. Magnificent activity!
timberland outlet
I not to mention my guys have already been looking at the excellent recommendations located on your web page and unexpectedly got a horrible suspicion I never expressed respect to you for those tips. All of the young boys had been as a consequence stimulated to study all of them and have in effect actually been using those things. Thank you for indeed being so considerate as well as for going for some very good ideas millions of individuals are really eager to know about. Our own honest apologies for not saying thanks to you sooner.
BrentKMaltby
Your means of describing everything with this article is truly nice,
every one can simply be aware of it, Thanks
a whole lot.
Also visit my homepage – BrentKMaltby
JamieVBomzer
Wow! Ultimately I bought a weblog where I can actually take valuable facts regarding my study and data.
Have a look at my web-site; JamieVBomzer
DanaNRonsini
Hey there would you mind letting me know which webhost you’re
utilizing? I’ve loaded your blog site in 3 completely different internet browsers and I have to admit this blog loads a
lot quicker then most. Is it possible to suggest an excellent
internet hosting provider in a honest price? Thanks, I
appreciate it!
My homepage: DanaNRonsini
chic sparrow sidekick
Hey! I could have sworn I’ve gone to this website before but after checking through a
number of the post I realized it’s a novice to me. Anyways, I’m definitely
happy I found it and I’ll be bookmarking and checking back frequently!
Also visit my site – chic sparrow sidekick
notebook wallet field notes
This design is incredible! You most definitely understand how
to keep a reader amused. Involving the wit
and your videos, I found myself almost transferred to start my own blog
(well, almost…HaHa!) Wonderful job. I seriously loved everything
you were required to say, and more than that, the way you presented it.
Too cool!
Feel free to visit my blog :: notebook wallet field notes
best refillable notebook a5
If some one needs to get updated with most up-to-date technologies
next he must be pay a fast visit this website and also be
up-to-date every day.
my blog; best refillable notebook a5
a5 dotted notebook bullet journal
Thanks a lot for sharing this with all of us you actually realize what
you are talking approximately! Bookmarked.
Kindly additionally visit my site =). We could have a link exchange
arrangement between us
My homepage :: a5 dotted notebook bullet journal
college ruled notebook paper size
Good post. I’m experiencing some of these issues as
well..
My web page: college ruled notebook paper size