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
- dialog box type
- Test page
- 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!