Selenium Test (Java)--drop-down box (21)

Source: Internet
Author: User
Tags id3

Example:

<! DOCTYPE html>function Calcresult () {var num1= document.getElementById ("Id1"). Value; var Calctag= document.getElementById ("Id2"). Value; var num2= document.getElementById ("ID3"). Value; var result= 0; Switch(Calctag) { Case"+": Result= parseint (NUM1) +parseint (num2);  Break;  Case"-": Result= parseint (NUM1)-parseint (num2);  Break;  Case"*": Result= parseint (NUM1) *parseint (num2);  Break;  Case"/":            if(parseint (num2) = = 0) {alert ("Number 2 cannot be 0"); } Else{result= parseint (NUM1)/parseint (num2); }             Break; default: Alert ("......"); } document.getElementById ("ID5"). Value =result; }</script>Number 1:<input type= "text" id= "ID1" name= "Num1"/> <select id= "Id2" name= "Calc" > <option value= " + "selected=" selected "> Plus </option> <option value="-"> Minus </option> <option value = "*" > Multiply </option> <option value= "/" > except </option> </select>Number 2:<input type= "text" id= "ID3" name= "num2"/> <input type= "button" Name= "is" id= "Id4" value= "=" onclick= "cal Cresult () "/>Results:<input type= "text" id= "ID5" name= "result"/> </form></body>

Code:

 PackageCom.test.select;ImportJava.util.Iterator;Importjava.util.List;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver;ImportOrg.openqa.selenium.support.ui.Select; Public classSelecttest { Public Static voidMain (string[] args) {Webdriver driver=NewFirefoxdriver (); Driver.get ("File:///D:/10-selenium/workspace/SeleniumTest/src/com/test/select/calc.html");        Driver.manage (). window (). Maximize (); Driver.findelement (By.id ("Id1")). SendKeys ("4")); Select sel=NewSelect (Driver.findelement (By.name ("Calc")))); Sel.selectbyvalue ("/"); Driver.findelement (By.id ("ID3")). SendKeys ("2")); Driver.findelement (By.id ("Id4") . Click (); System.out.println (Driver.findelement (By.id ("ID5")). GetAttribute ("value"))); ////////////////////////////////////////////////////////////////Driver.findelement (By.id ("Id1") . Clear (); Driver.findelement (By.id ("Id1")). SendKeys ("3")); Select Sel2=NewSelect (Driver.findelement (By.name ("Calc")))); Sel2.selectbyvalue ("+"); Driver.findelement (By.id ("ID3") . Clear (); Driver.findelement (By.id ("ID3")). SendKeys ("1")); Driver.findelement (By.id ("Id4") . Click (); System.out.println (Driver.findelement (By.id ("ID5")). GetAttribute ("value"))); ////////////////////////////////////////////////////////////////Driver.findelement (By.id ("Id1") . Clear (); Driver.findelement (By.id ("Id1")). SendKeys ("5")); Select Sel3=NewSelect (Driver.findelement (By.name ("Calc")))); Sel3.selectbyvalue ("*"); Driver.findelement (By.id ("ID3") . Clear (); Driver.findelement (By.id ("ID3")). SendKeys ("6")); Driver.findelement (By.id ("Id4") . Click (); System.out.println (Driver.findelement (By.id ("ID5")). GetAttribute ("value"))); ////////////////////////////////////////////////////////////////Driver.findelement (By.id ("Id1") . Clear (); Driver.findelement (By.id ("Id1")). SendKeys ("100")); Select Sel4=NewSelect (Driver.findelement (By.name ("Calc")))); Sel4.selectbyvalue ("-"); Driver.findelement (By.id ("ID3") . Clear (); Driver.findelement (By.id ("ID3")). SendKeys ("1")); Driver.findelement (By.id ("Id4") . Click (); System.out.println (Driver.findelement (By.id ("ID5")). GetAttribute ("value"))); ////////////////////////////////////////////////////////////////////////////////Select Selall =NewSelect (Driver.findelement (By.name ("Calc")))); List<WebElement> lw=selall.getoptions (); Iterator<WebElement> iterator =Lw.iterator ();  while(Iterator.hasnext ()) {System.out.println (Iterator.next (). GetAttribute ("Value"));    } driver.quit (); }        }

Results:

499+-*/

Selenium Test (Java)--drop-down box (21)

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.