Java Selenium (11) Action Popup dialog box

Source: Internet
Author: User
Tags gettext xpath

Web developers often need to use JavaScript pop-up dialogs to give users some information, including the following types

Read Catalogue

dialog box type

1. Warning Box: Validation results, errors or warnings that are used to prompt the user for relevant information

2. Prompt box: Used to prompt the user to enter data in the current dialog box, generally requires the user to click the Cancel or Confirm button

3. Confirm box: Used to prompt the user to confirm or cancel an action, generally require the user to click the Cancel or Confirm button

Test page

Use the following page as an example to explain, including the warning box, prompt box, confirmation box

Http://sislands.com/coin70/week1/dialogbox.htm

Selenium Code for the Action dialog box

     Public Static voidTestalert (webdriver driver) {String URL= "Http://sislands.com/coin70/week1/dialogbox.htm";                Driver.get (URL); Webelement Alertbutton= Driver.findelement (By.xpath ("//input[@value = ' alert ']"));                Alertbutton.click (); Alert Javascriptalert=Driver.switchto (). alert ();        System.out.println (Javascriptalert.gettext ());    Javascriptalert.accept (); }         Public Static voidTestprompt (Webdriver driver)throwsException {String URL= "Http://sislands.com/coin70/week1/dialogbox.htm";                Driver.get (URL); Webelement Promptbutton= Driver.findelement (By.xpath ("//input[@value = ' Prompt ']"));        Promptbutton.click (); Thread.Sleep (2000); Alert javascriptprompt=Driver.switchto (). alert (); Javascriptprompt.sendkeys ("This is learning Selenium");                    Javascriptprompt.accept ();                System.out.println (Javascriptprompt.gettext ()); Javascriptprompt=Driver.switchto (). alert ();                Javascriptprompt.accept (); Thread.Sleep (2000);        Promptbutton.click (); Javascriptprompt=Driver.switchto (). alert ();        Javascriptprompt.dismiss (); Thread.Sleep (2000); Javascriptprompt=Driver.switchto (). alert ();    Javascriptprompt.accept (); }         Public Static voidTestconfirm (Webdriver driver)throwsException {String URL= "Http://sislands.com/coin70/week1/dialogbox.htm";                Driver.get (URL); Webelement ConfirmButton= Driver.findelement (By.xpath ("//input[@value = ' Confirm ']"));        Confirmbutton.click (); Thread.Sleep (2000); Alert javascriptconfirm=Driver.switchto (). alert ();        Javascriptconfirm.accept (); Thread.Sleep (2000); Javascriptconfirm=Driver.switchto (). alert ();    Javascriptconfirm.accept (); }

Java Selenium (11) Action Popup dialog box

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.