Recall & Review
beginner
What is XPath in Selenium?
XPath is a way to find elements on a web page by navigating the HTML structure using paths and conditions.
Click to reveal answer
beginner
How do you write an XPath to find an element with a specific attribute value?
Use the syntax:
//tagname[@attribute='value']. For example, //input[@id='username'] finds an input element with id 'username'.Click to reveal answer
beginner
What does this XPath mean?
//button[@type='submit']It finds all
button elements on the page that have an attribute type with the value submit.Click to reveal answer
intermediate
How can you find an element with multiple attribute conditions using XPath?
Use
and inside the brackets: //tagname[@attr1='value1' and @attr2='value2']. For example, //input[@type='text' and @name='email'].Click to reveal answer
beginner
Why is using attributes in XPath locators helpful in Selenium tests?
Attributes help find elements precisely and reliably, even if the page layout changes, making tests more stable.
Click to reveal answer
Which XPath expression finds a div with class 'header'?
✗ Incorrect
The correct syntax uses @ to specify the attribute:
//div[@class='header'].How do you select an input element with name 'password' and type 'password' using XPath?
✗ Incorrect
Use
and inside one bracket to combine conditions: //input[@name='password' and @type='password'].What does this XPath select?
//a[@href]✗ Incorrect
It selects all
a tags that have an href attribute, regardless of its value.Which XPath is correct to find a button with id 'submitBtn'?
✗ Incorrect
Attributes must be prefixed with @ and values in quotes:
//button[@id='submitBtn'].Why avoid using XPath with only tag names for locating elements?
✗ Incorrect
Using only tag names can select multiple elements, making tests less reliable.
Explain how to write an XPath expression to locate an element by a single attribute.
Think about how you tell Selenium to find an element with a specific attribute.
You got /5 concepts.
Describe how to combine multiple attribute conditions in an XPath locator.
Remember how to say 'and' in XPath conditions.
You got /4 concepts.