Basic Tasks for Locators & XPath
Traversing in Selenium
1. Task: Locate Elements Using ID
Question:
Open a website of your choice (e.g., Flipkart or Amazon or Dot portal in wipro laptop).
Identify and interact with the following elements using their ID attributes:
- Search box
- Login button
Expected Output:
The search box should be identified using the ID locator and text should be entered. The
Login button should be identified using the ID locator and clicked.
2. Task: Locate Elements Using Name
Question:
Identify elements on the website that have a Name attribute:
- Search box
- Submit button (if available)
Expected Output:
The element should be identified using the Name locator, and you should be able to interact
with it (e.g., entering text or clicking).
3. Task: Locate Elements Using Link Text
Question:
On the webpage, identify any links using Link Text. Perform the following tasks:
- Find a link with the exact visible text (e.g., "Login", "Sign Up").
- Click on the link.
Expected Output:
The link should be clicked after identification by its full link text.
4. Task: Locate Elements Using Partial Link Text
Question:
Identify links on the webpage using Partial Link Text. Perform the following:
- Find a link with partial visible text (e.g., "Sign", "Log").
- Click on the link.
Expected Output:
The link should be clicked using partial link text matching.
5. Task: Locate Elements Using XPath (Basic)
Question:
Identify elements using both absolute and relative XPath. Tasks include:
- Find the search box using relative XPath.
- Find a button using absolute XPath.
- Perform actions (such as entering text or clicking) on these elements.
Expected Output:
The elements should be identified and interacted with using XPath expressions.
6. Task: Locate and Traverse Elements Using XPath Axes
Question:
Using XPath axes, perform the following tasks:
1. 1. Following-sibling: Identify an element (like a button) and find its following sibling
(e.g., a checkbox or another button).
2. Preceding-sibling: Identify an element and find its preceding sibling (e.g., text before a
button).
3. Descendant: Find an element and locate its descendants (e.g., all links or buttons
within a specific section).
Expected Output:
You should be able to traverse through sibling and descendant elements and perform
actions on them.
7. Task: Interact with Input Fields and Buttons Using Different Locators
Question:
Using any locator (ID, Name, Link Text, Partial Link Text, or XPath), perform the following
tasks on a web page:
- Find and fill out a search box.
- Find and click the "Submit" or "Search" button.
- Verify the actions (e.g., check if the correct page opens after search).
Expected Output:
Elements should be identified using different locator strategies, and you should be able to
perform the appropriate interactions.