0
0
Selenium Pythontesting~20 mins

Find element by XPath in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XPath Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
locator
intermediate
2:00remaining
Identify the correct XPath to select a button with text 'Submit'
Which XPath expression correctly selects a button element with the exact visible text 'Submit'?
A//button[text()='Submit']
B//button[contains(text(),'Submit')]
C//button[@name='Submit']
D//button[@value='Submit']
Attempts:
2 left
💡 Hint
Look for an XPath that matches the exact text inside the button element.
assertion
intermediate
2:00remaining
Check if element found by XPath is visible
Given the Selenium code below, what assertion correctly verifies the element found by XPath is visible on the page?
Selenium Python
element = driver.find_element(By.XPATH, "//div[@id='content']")
Aassert element is None
Bassert element.is_displayed()
Cassert element.text == ''
Dassert element.is_enabled()
Attempts:
2 left
💡 Hint
Visibility means the element is shown on the page, not just present in the HTML.
Predict Output
advanced
2:00remaining
Output of Selenium find_elements with XPath returning multiple matches
What is the output type of the following Selenium Python code snippet if the XPath matches three elements on the page?
Selenium Python
elements = driver.find_elements(By.XPATH, "//ul[@id='menu']/li")
print(type(elements))
print(len(elements))
A<class 'list'>\n1
B<class 'WebElement'>\n1
C<class 'WebElement'>\n3
D<class 'list'>\n3
Attempts:
2 left
💡 Hint
find_elements returns a list of elements, even if multiple are found.
🔧 Debug
advanced
2:00remaining
Identify the error in XPath expression causing NoSuchElementException
Why does the following Selenium code raise a NoSuchElementException?
Selenium Python
element = driver.find_element(By.XPATH, "//div[@class='container'][@id='main']")
AXPath syntax error: multiple predicates should be combined with 'and' inside one []
BThe element does not exist on the page
CMissing quotes around attribute values
DUsing find_element instead of find_elements causes the error
Attempts:
2 left
💡 Hint
Check how multiple attribute conditions are combined in XPath.
framework
expert
2:00remaining
Best practice for waiting for element by XPath in Selenium Python
Which code snippet correctly waits up to 10 seconds for an element located by XPath to be visible before interacting with it?
Aelement = driver.find_element(By.XPATH, "//input[@name='email']"); assert element.is_displayed()
Belement = driver.find_element(By.XPATH, "//input[@name='email']"); time.sleep(10)
Celement = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='email']")))
Delement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@name='email']")))
Attempts:
2 left
💡 Hint
Waiting for visibility ensures the element can be interacted with, not just present in the DOM.