The positioning of elements in the robot framework.
Because the robot framework introduces the SELENIUM2 package, if we learn selenium, the positioning is the same. Because did not find the relevant information, so, after the authentication ID, name, XPath, CSS Four positioning method is possible, especially the latter two are "omnipotent", so you can solve the positioning problem of 99%.
ID and name Locator
If you think of an element as a person, the ID and name can be considered as a person's ID number and name. Of course, whether these attribute values are unique depends on how the front-end engineer is designed.
Baidu Search box and search button
... <input id= "KW1" class= "S_ipt" type= "text" maxlength= "" "Name=" WD "autocomplete=" Off "> ...
<input id= "SU1" class= "bg s_btn" type= "Submit" onmouseout= "This.classname= ' bg s_btn '" onmousedown= "this.classname= ' BG s_btn s_btn_h ' "value=" Baidu a Bit "> ...
According to the above example, the Baidu input box can take the ID or name to locate. (only if the value of ID and name is unique on the page)
id = kw1
Name = WD
This is written in the robot framework:
Input Text |
Id=kw1 |
Robot Framework Learning |
Input text |
Name=wd |
Robot Framework Learning |
Input text is used to enter the key word for the box, "Robot Framework Learning" is the content to be entered into the input box.
Baidu button only ID data can be used:
Id=su1
The click button is the keyword for the click of the buttons.
XPath positioning
If a person does not have a ID number without a name how to find it. Think about how you find a friend to eat, his cell phone is not through, the phone does not return. Go directly to his home, then you must have his home address, xx xx district xx road xx number. Xpath can find elements through this hierarchical relationship.
Take a look at the location of the Baidu input box on the entire page:
1, the absolute path of XPath:
Xpath =/html/body/div[1]/div[4]/div[2]/div/form/span[1]/input
We can start looking from the outermost layer, under the body of the HTML below the div below the 4th div below the .... Input tag. The desired element is found through a lock on the first level.
2. The relative path of XPath:
The use of absolute paths is often used when we are forced to do so. Most of the time it's easier to use a relative path.
2.1. The element itself:
XPath can also take advantage of the attributes of the element itself:
Xpath =//*[@id = ' kw1 ')
Represents a level, * denotes a label name. @id =KW1 indicates that this element has an ID equal to KW1.
Of course, the label name can also be set:
Xpath =//input[@id = ' kw1 ')
Element itself, the attributes that can be leveraged are not limited to the ID and name, such as:
Xpath =//input[@type = ' text ']
Xpath =//input[@autocomplete = ' off ']
But make sure that these elements can uniquely identify an element.
2.2, to find the superior:
When we are looking for a person who is a newborn baby, has not named the child has not entered the account (Social Security number), but you will always be with your father's side, your father has a unique name and ID number, so we can find your father, naturally found you.
The ancestor attributes of the element are:
<form id= "Form1" class= "FM" action= "/S" name= "F1" >
<span Class