This article describes how we use selenium to manipulate various page elements
Reading Table of Contents
- Links (Link)
- Input Box textbox
- Buttons (Button)
- Drop-down selection box (select)
- Radio buttons (Radio button)
- Multi-marquee check box
Links (Link)
<div>
<p> links link</p>
<a href= "Www.cnblogs.com/tankxiao" > Small tank </a>
</ Div>
Linked actions
Find link element
webelement link1 = driver.findelement (By.linktext ("Small Tank"));
Webelement link11 = driver.findelement (By.partiallinktext ("Tank"));
Click on the link
Link1.click ();
Input Box textbox
<div>
<p> input box testbox</p>
<input type= "text" id= "Usernameid" value= "username"/>
</div>
The action of the input box
Find element
webelement = driver.findelement (By.id ("Usernameid"));
Enter the content in the input box
element.sendkeys ("test111111");
Empty the input box
element.clear ();
Gets the content
element.getattribute ("value") of the input box;
Buttons (Button)
<div>
<p> button button</p>
<input type= "button" value= "Add" id= "Proadditem_0"/>
Find the button element
Find the button element
String xpath= "//input[@value = ' add ']";
Webelement AddButton = driver.findelement (By.xpath (XPath));
Click on the button
Addbutton.click ();
Determine if the button is enable
addbutton.isenabled ();
Drop-down selection box (select)
<div>
<p> drop-down selection box select</p>
<select id= "Proadditem_kind" name= "kind" >
< Option value= "1" > Computer hardware </option>
<option value= "2" > Real estate </option>
<option value= "18" > Type aa</option>
<option value= "A" > Kind bb</option>
<option value= "A" > Kind bb</ option>
<option value= "> Type cc</option>
</select>
</div>
Action of the Drop-down selection box
Find the element
Select select = New Select (Driver.findelement (by.id ("Proadditem_kind")));
Select the corresponding selection, index
Select.selectbyindex (2) starting from 0;
Select.selectbyvalue ("a");
Select.selectbyvisibletext ("kind AA");
Get all the options
list<webelement> = Select.getoptions ();
for (Webelement webelement:options) {
System.out.println (Webelement.gettext ());
}
Radio buttons (Radio button)
<div>
<p> single option Radio button</p>
<input type= "Radio" value= "Apple" name= "fruit>"/> Apple
<input type= "Radio" value= "Pear" name= "fruit>"/>pear "<input" type= "Radio" value= "Banana"
Name= "fruit>"/>banana
<input type= "Radio" value= "Orange" name= "fruit>"/>orange
</div >
Action for a single OPTION element
Locate the Radio box element
String xpath= "//input[@type = ' Radio '] [@value = ' Apple ']";
Webelement Apple = driver.findelement (By.xpath (XPath));
Select a single marquee
Apple.click ();
Determines whether a single marquee has been selected
Boolean isappleselect = apple.isselected ();
Gets the element attribute
Apple.getattribute ("value");
Multi-marquee check box
<div>
<p> Multi-option checkbox</p>
<input type= "checkbox" value= "Apple" name= "fruit>"/> Apple
<input type= "checkbox" value= "Pear" name= "fruit>"/>pear <input type=
"checkbox" Value= " Banana "Name=" fruit> "/>banana
<input type=" checkbox "value=" Orange "name=" fruit> "/>orange
</div>
The operation of the multiple-selection box is the same as the one of the marquee, which is no longer spoken here.
The above is the Java Selenium Common Web UI element operation data collation, follow-up continue to add, thank you for your support for this site!