Enter box: input
? Representation: 1. In HTML: <input id= "User" type= "text" >
? Main operation:
1. Driver.findelement (by. ID ("user")). SendKeys ("test");
2. Driver.findelement (by.id ("User")). Clear ()
? Description
1. SendKeys represents input, parameter is the value to be entered
2. Clear indicates that the data in the input box is cleared
1 Public voidtestinput (String x)2 {3 //the missing part is SendKeys without parameters.4 //driver.findelement (By.xpath (".//*[@id = ' kw ']). SendKeys (New string[]{"SELENIUM2 Training"});5 6 //In this way, you can input the content you want to use into the testinput in the main function .7Driver.findelement (By.xpath (".//*[@id = ' kw ')"). SendKeys (Newstring[]{x});8Driver.findelement (By.xpath (".//*[@id = ' su ']") . Click ();9}
View Code
Hyperlink: A
? form of expression:
1. In HTML generally: <a class= "Baidu" href= "http://www.baidu.com" >baidu</a>
? Main operation:
1. Driver.findelement (By.xpath ("//div[@id = ' link ']/a"). Click ();
? Description: 1. Click on the "a" link
1 Public void Testlink () 2 {3 driver.findelement (By.xpath (".//*[@id = ' 1 ']/h3/a")). Click (); 4 }
View Code
Drop-down menu: Select
? form of expression:
1. In HTML, the general is:
<select name= "Select" >
<option value= "Volvo" >Volvo</option>
<option value= "Saab" >Saab</option>
<option value= "Opel" >Opel</option>
<option value= "Audi" >Audi</option>
</select>
Introduction to Basic controls
? Main operation:
webelement element = Driver.findelement (By.cssselector ("Select[name= ' select ')");
Select select = New Select (element);
Select.selectbyvalue ("Opel");
Select.selectbyindex (2);
Select.selectbyvisibletext ("Opel");
? Description
1. A class that requires a select
2. The Selectbyvalue parameter is the Value property in option
3. The Selectbyindex parameter is the order of option
4. The Selectbyvisibletext parameter is the text value of option
1 Public voidtestoption ()2 {3 //webelement elements=driver.findelement (by.id ("addr_province"));4Webelement elements=driver.findelement (By.cssselector ("Select[name= ' addr_province ')"));5Select select=NewSelect (elements);6Select.selectbyvalue ("Tianjin");7 //Select.selectbyindex (5);8 //Select.selectbyvisibletext ("Fujian province");9 Ten //using list traversal One /* A List options=select.getoptions (); - int optionsize=options.size (); - int i; the For (i=0;i<optionsize;i++) - { - Select.selectbyindex (i); - } + */ -}
View Code
Radio: Radiobox
? form of expression:
1. In HTML, the general is:
<input class= "Volvo" type= "Radio" Name= "Identity" >
? Main operation:
list<webelement> elements = driver.findelements (By.name ("Identity"));
Elements.get (2). Click (); Boolean select = Elements.get (2). isSelected ();
? Description
1. Click to select this radio box
2. The IsSelected representative checks whether this radio box is selected
1 Public voidTestradio ()2 {3 //need to consider how to locate the Limit_area with Cssseletor4Webelement radio=driver.findelement (by.id ("Limit_area"));5Radio.findelement (By.id ("Limitqy") . Click ();6 //Whether the radio box is selected7 //radio.isselected ();8}
View Code
Multiple selection: checkbox
? form of expression:
1. In HTML generally: <input type= "checkbox" Name= "CheckBox1" >
? Main operation:
list<webelement> elements = driver.findelements (By.xpath ("//div[@id = ' checkbox ']/input"));
webelement element = Elements.get (2);
Element.click ();
Boolean check = element.isselected ();
? Description
1. Click to select this multi box
2. isselected representative checks if the marquee is selected
1 Public voidTestcheckbox ()2 {3 //positioning can then be used to optimize the CSS mode4 5 //A6 //webelement check=driver.findelement (By.xpath (".//input[@type = ' checkbox ']);7 //check.findelement (by.id ("Shop_all")). Click ();8 9 //BTenList<webelement> check=driver.findelements (By.xpath (".//div[@class = ' Inputarea ']//input[@type = ' checkbox ']")); One intChecksize=check.size (); A inti; - for(i=0;i<checksize;i++) - { theWebelement element=(webelement) check.get (i); - Element.click (); - } - +}
View Code
Buttons: button
? form of expression:
1. In HTML, there are generally two forms of representation:
<input class= "button" type= "button" disabled= "Disabled" value= "Submit" >
<button class= "button" disabled= "Disabled" > submit</button>
? Main operation:
webelement element = Driver.findelement (by.classname ("button"));
Element.click ();
Boolean button = Element.isenabled ();
? Description
1. Click on this button
2. IsEnabled representative Check if this button is available
SELENIUM2 Basic API Introduction