0
0
Selenium Pythontesting~10 mins

XPath with text() in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find an element by exact text using XPath.

Selenium Python
element = driver.find_element(By.XPATH, "//button[text()=[1]]")
Drag options to blanks, or click blank then click option'
A'submit'
B"Submit"
C"submit"
D'Submit'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes inside double quotes without escaping causes syntax errors.
Using incorrect case in text() causes no match.
2fill in blank
medium

Complete the code to find a link element containing partial text using XPath.

Selenium Python
element = driver.find_element(By.XPATH, "//a[contains(text(), [1])]")
Drag options to blanks, or click blank then click option'
A"learn more"
B'Learn More'
C'learn more'
D"Learn More"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the text inside contains() causes syntax errors.
Using wrong case in text causes no match.
3fill in blank
hard

Fix the error in the XPath expression to find a div with exact text 'Welcome'.

Selenium Python
element = driver.find_element(By.XPATH, "//div[text()=[1]]")
Drag options to blanks, or click blank then click option'
A'Welcome'
B"Welcome"
CWelcome
D'welcome'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the text inside text() causes XPath syntax errors.
Using wrong case in text causes no match.
4fill in blank
hard

Fill both blanks to find a span element with text exactly 'Hello' and class 'greeting'.

Selenium Python
element = driver.find_element(By.XPATH, "//span[text()=[1] and @class=[2]]")
Drag options to blanks, or click blank then click option'
A'Hello'
B"Hello"
C'greeting'
D"greeting"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting text() or attribute values causes XPath errors.
Mixing quote types incorrectly causes syntax errors.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps button text to their ids for buttons containing 'Click'.

Selenium Python
buttons = driver.find_elements(By.XPATH, "//button[contains(text(), [1])]")
result = [2]: [3] for btn in buttons}
Drag options to blanks, or click blank then click option'
A'Click'
Bbtn.get_attribute('id')
Cbtn.text
Dbtn.text()
Attempts:
3 left
💡 Hint
Common Mistakes
Using btn.text() instead of btn.text causes attribute errors.
Not quoting the text in XPath causes syntax errors.
Swapping key and value in dictionary comprehension.