if i given invalid data how to get alert in selenium using java

+1 vote

valid data i am using 

driver.switchTo().alert().getText();

but i want invalid data also exicute next continue to valid data also , how i will get alert message 

Jul 18, 2020 in Java by anonymous
• 130 points
1,216 views

1 answer to this question.

0 votes

Hello,

Here is some of the method you can go for.

Alert interface provides the below few methods which are widely used in Selenium Webdriver.

1) void dismiss() // To click on the 'Cancel' button of the alert.

driver.switchTo().alert().dismiss();

2) void accept() // To click on the 'OK' button of the alert.

driver.switchTo().alert().accept();

3) String getText() // To capture the alert message.

driver.switchTo().alert().getText();

4) void sendKeys(String stringToSend) // To send some data to alert box.

driver.switchTo().alert().sendKeys("Text");

Hope it helps!!

Thank You!!

answered Jul 20, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
2,923 views
0 votes
1 answer

How to encode data using Base64 in Java?

import org.apache.commons.codec.binary.Base64; We can not use sun.* packages ...READ MORE

answered May 30, 2018 in Java by Sushmita
• 6,920 points
1,062 views
+2 votes
1 answer

How do I ask the Selenium-WebDriver to wait for few seconds in Java?

There are two ways to wait: explicit ...READ MORE

answered Dec 19, 2018 in Java by Daisy
• 8,140 points

edited Dec 19, 2018 by Daisy 950 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,310 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer

How to get comments by given user in Facebook Graph API? Can we get list of comments made by given user?

Hii kartik, You can get the list of ...READ MORE

answered May 7, 2020 in Java by Niroj
• 82,840 points
12,712 views
0 votes
1 answer

How to get the windows native look in Java GUI programming?

Hello Kartik,  You can try the syntax: UIManager.setLookAndFeel(PLAF); (Pluggable ...READ MORE

answered May 7, 2020 in Java by Niroj
• 82,840 points
1,119 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP