Selenium is an automation testing framework for web and mobile apps. Selenium scripts are written in java/php/ruby/c# etc
e.g. Registration page: There are 3 html input elements, userid, password and email address.
Steps to enter data in input objects:
1.Script will open the page
2. Script will identify the input element
3. Script will then enter data in input element
So the question is how selenium code identifies the input elements? The answer is Xpath or CSS Seector.
In Xpath: html code is treated like a document having ancestor, desendent, parent, grand parent, child, grand child, sibling, following sibling.
So to identify an element e.g. userid textbox: <input type="text" id="userid" /> we need to write //input[@id="userid"]
- Find input element which has id=userid: //input[@id="userid"]
- Parent and grand parents of current element till root node: /ancestor::
- Child & grand child of current node till current element closes: /descendent::
- All tags after the current element till html document end: /preceding::
- Only one immediate parent: /parent::
- One or more level 1 children till current element closes: /Child::
- All tags after the current element till document end: /following::
- Same level following sibling till document end: /following-sibling::