Java Selenium Action Pop-up dialog box example to explain _java

Source: Internet
Author: User
Tags gettext xpath

Web developers often need to use the JavaScript pop-up dialog box to give users some informational hints, including the following types

Reading Table of Contents

    1. dialog box type
    2. Test page
    3. Code for the Selenium Action dialog box

dialog box type

1. Warning Boxes: Validation results, errors or warnings for prompting user related information

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

3. Confirmation box: Used to prompt the user to confirm or cancel an operation, generally require the user to click Cancel or confirm the 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

Code for the Selenium Action dialog box

 public static void Testalert (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 void Testprompt (Webdriver driver) throws Exception {String url= "Http://sislands.com/coin70/week1/di
  Alogbox.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 void Testconfirm (Webdriver driver) throws Exception {String url= "http://sislands.com/coin70/week1/d
  Ialogbox.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 (); }

  Above is the Java Selenium Operation pop-up dialog box data collation, follow-up continue to add, thank you for your support to this site!

Related Article

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.