Java Selenium-Several dialog box handling alert\confirm\prompt

Source: Internet
Author: User

1. Alert, first use the normal method to locate the button that triggers the Alert, and then

Alert alert = Driver.switchto (). alert (); Alert.accept ();

If the alert box is confirmed, it is OK to pop the alert box continuously, continue the same operation, pay attention to the delay ... Otherwise it could be too fast, wrong, pit.

Alert alert = Driver.switchto (). alert (); Alert.accept (); Thread.Sleep (+); alert = Driver.switchto (). alert (); Alert.accept ();

2. Confirm

Alert confirm = Driver.switchto (). alert (); String Text1 = Confirm.gettext (); Get text System.out.println (Text1) on confirm; Confirm.accept (); Close confirm

3. Prompt

Alert prompt = Driver.switchto (). alert ();
Prompt.sendkeys ("OK!!!!") Input value, if input is supported prompt.accept (); Close prompt

 

The essence of them is the same, Driver.switchto (). alert () This sentence can get the object of the Alert\confirm\prompt dialog box, and then use its method to manipulate it. The main methods of dialog operations are:
. GetText () gets its text value
. Accept () is equivalent to clicking on its "Confirm"
. Dismiss () is equivalent to clicking "Cancel" or cross-off the dialog box
. SendKeys () input value, this alert\confirm can not be used, will error.

 

Java Selenium-Several dialog box handling alert\confirm\prompt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.