0
0
Selenium Pythontesting~20 mins

XPath with text() in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XPath Text() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this XPath query?
Given the HTML snippet below, what will the XPath //button[text()='Submit'] select?
Selenium Python
<button>Submit</button>
<button>submit</button>
<button> Submit </button>
ASelects only the first <button> element
BSelects all three <button> elements
CSelects no elements
DSelects the second <button> element only
Attempts:
2 left
💡 Hint
Remember that XPath text() matches exact text content including case and spaces.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the presence of a button with text 'Cancel' using XPath?
You want to assert that a button with text 'Cancel' exists on the page using Selenium and XPath. Which assertion is correct?
Selenium Python
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
Await.until(EC.presence_of_element_located((By.XPATH, "//button[text()='cancel']")))
Bwait.until(EC.presence_of_element_located((By.XPATH, "//button[text()='Cancel']")))
Cwait.until(EC.presence_of_element_located((By.XPATH, "//button[contains(text(),'Cancel')]") ))
Dwait.until(EC.presence_of_element_located((By.XPATH, "//button[text()=' Cancel ']") ))
Attempts:
2 left
💡 Hint
XPath text() is case-sensitive and matches exact text.
locator
advanced
2:00remaining
Which XPath locator correctly selects a
containing exact text 'Error 404'?
Choose the XPath expression that selects a
element whose text content is exactly 'Error 404'.
A//div[text()='Error 404']
B//div[contains(text(),'Error 404')]
C//div[text()=' error 404']
D//div[text()='Error404']
Attempts:
2 left
💡 Hint
Exact text matching requires exact string including case and spaces.
🔧 Debug
advanced
2:00remaining
Why does this XPath fail to find the element?
Given the XPath //span[text()='Login'] does not find the element, but the element's visible text is 'Login'. What is the likely cause?
Selenium Python
<span> Login </span>
AThe XPath fails because <span> elements cannot be selected by text()
BThe XPath fails because 'Login' is case-insensitive in XPath
CThe XPath fails because the text has leading/trailing spaces not matched by text()
DThe XPath fails because the element is hidden
Attempts:
2 left
💡 Hint
Check for spaces around the text inside the element.
framework
expert
3:00remaining
Which Selenium Python code snippet correctly waits for a button with exact text 'Submit' to be clickable?
Select the correct code snippet that waits up to 15 seconds for a button with text 'Submit' to be clickable using Selenium WebDriverWait and XPath.
AWebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='submit']")))
BWebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//button[text()=' Submit ']") ))
CWebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Submit')]") ))
DWebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Submit']")))
Attempts:
2 left
💡 Hint
Use exact text match and correct XPath syntax.