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 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/coin 70/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 void Testconfirm (Webdriver driver) throws Exception {String url= "Http://sislands.com/coi N70/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