Recall & Review
beginner
What is XPath in Selenium?
XPath is a language used to locate elements on a web page by navigating through the HTML structure.
Click to reveal answer
beginner
How do you find an element by XPath in Selenium with Python?
Use driver.find_element(By.XPATH, 'your_xpath_here') to locate the element.
Click to reveal answer
intermediate
What is the difference between absolute and relative XPath?
Absolute XPath starts from the root element and follows the full path, while relative XPath starts from anywhere in the document and is shorter and more flexible.
Click to reveal answer
intermediate
Why should you prefer relative XPath over absolute XPath?
Relative XPath is less fragile and more maintainable because it does not depend on the full path, which can change often.
Click to reveal answer
beginner
Give an example of a valid XPath to find a button with text 'Submit'.
Example: //button[text()='Submit']
Click to reveal answer
Which Selenium method is used to find an element by XPath in Python?
✗ Incorrect
The correct method to find an element by XPath is driver.find_element(By.XPATH, 'xpath').
What does the XPath expression //div[@class='header'] select?
✗ Incorrect
The expression selects all div elements that have a class attribute equal to 'header'.
Which XPath is an example of absolute XPath?
✗ Incorrect
Absolute XPath starts from the root and follows the full path, like /html/body/div[1]/div[2]/button.
Why is relative XPath preferred over absolute XPath?
✗ Incorrect
Relative XPath is shorter and more flexible, so it is less likely to break when the page structure changes.
What does the XPath //input[@type='checkbox'] select?
✗ Incorrect
It selects all input elements where the type attribute is 'checkbox'.
Explain how to find an element by XPath in Selenium using Python.
Think about the Selenium method and locator type.
You got /3 concepts.
Describe the difference between absolute and relative XPath and why one is preferred.
Consider how page changes affect XPath.
You got /3 concepts.