Recall & Review
beginner
What does the XPath function
text() do?The
text() function in XPath selects the text content inside an element. It helps locate elements by matching their visible text.Click to reveal answer
beginner
Write an XPath to find a button with the exact text 'Submit'.
Use
//button[text()='Submit']. This finds a button element whose text is exactly 'Submit'.Click to reveal answer
intermediate
How do you find an element containing text 'Login' anywhere inside it using XPath?
Use
//*[contains(text(), 'Login')]. This finds any element where the text includes 'Login' anywhere inside.Click to reveal answer
beginner
Why is using
text() in XPath useful for testing?It helps find elements by their visible text, which is often stable and user-friendly. This makes tests easier to read and maintain.
Click to reveal answer
intermediate
What is a limitation of using
text() in XPath?If the element has nested tags or extra spaces,
text() might not match exactly. You may need to use normalize-space() or other functions.Click to reveal answer
Which XPath expression finds a
div with exact text 'Hello World'?✗ Incorrect
Option C uses
text()='Hello World' to match exact text inside the div.What does
//*[contains(text(),'Click')] select?✗ Incorrect
It selects any element whose text contains 'Click' anywhere inside.
Why might
text() fail to match an element's visible text?✗ Incorrect
Nested tags or spaces can cause
text() to not match exactly.Which function helps remove extra spaces when using
text() in XPath?✗ Incorrect
normalize-space() removes leading and trailing spaces and normalizes internal spaces.In Selenium Python, how do you find an element with text 'Home' using XPath?
✗ Incorrect
Option A uses XPath with
text() to find element with exact text 'Home'.Explain how the XPath
text() function helps in locating elements during testing.Think about how you find buttons or links by their labels.
You got /3 concepts.
Describe a situation where using
text() in XPath might not work as expected and how to fix it.Consider complex HTML structures or formatting.
You got /3 concepts.