0
0
Selenium Pythontesting~20 mins

Why form handling is common in testing in Selenium Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Form Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is form handling a frequent focus in software testing?

Forms are everywhere on websites and apps. Why do testers often focus on testing forms?

ABecause forms do not require any validation or testing since they are simple.
BBecause forms automatically fix bugs in the software when submitted.
CBecause forms collect user input which must be validated to prevent errors and security issues.
DBecause forms are the only way to navigate between pages in an application.
Attempts:
2 left
💡 Hint

Think about what happens when users enter data in forms and submit it.

Predict Output
intermediate
2:00remaining
What is the output of this Selenium Python code testing a form?

Given the code below, what will be printed after running the test?

Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
browser.get('https://example.com/login')
username = browser.find_element(By.ID, 'username')
password = browser.find_element(By.ID, 'password')
username.send_keys('user1')
password.send_keys('wrongpass')
password.send_keys(Keys.RETURN)
error = browser.find_element(By.ID, 'error-msg').text
print(error)
browser.quit()
ALogin successful.
BInvalid username or password.
CNo such element exception.
DEmpty string.
Attempts:
2 left
💡 Hint

Think about what happens when wrong credentials are submitted.

assertion
advanced
1:30remaining
Which assertion correctly verifies a form submission success message?

You want to check if the success message 'Form submitted!' appears after submitting a form. Which assertion is correct?

Selenium Python
success_message = driver.find_element(By.ID, 'success-msg').text
Aassert success_message != 'Form submitted!'
Bassert success_message == 'Form submitted!'
Cassert success_message is None
Dassert 'Form submitted!' in success_message
Attempts:
2 left
💡 Hint

Check if the expected text is part of the message, not necessarily the whole text.

locator
advanced
1:30remaining
Which locator is best to find a form input with label 'Email' for accessibility?

You want to locate the email input field in a form. The label has for='email' and the input has id='email'. Which locator is best?

Adriver.find_element(By.ID, 'email')
Bdriver.find_element(By.XPATH, "//input[@name='email']")
Cdriver.find_element(By.CSS_SELECTOR, 'input[type=text]')
Ddriver.find_element(By.CLASS_NAME, 'email-input')
Attempts:
2 left
💡 Hint

Use the locator that matches the input's unique id linked to the label.

🔧 Debug
expert
2:30remaining
Why does this Selenium test fail to submit the form?

Review the code below. The test tries to fill and submit a form but fails. What is the cause?

Selenium Python
driver.get('https://example.com/contact')
name_input = driver.find_element(By.NAME, 'name')
email_input = driver.find_element(By.NAME, 'email')
submit_button = driver.find_element(By.ID, 'submit')

name_input.send_keys('Alice')
email_input.send_keys('alice@example.com')
submit_button.click()

success = driver.find_element(By.ID, 'success-msg').text
print(success)
AThe submit button is inside an iframe and needs switching to that frame first.
BThe input fields have wrong names and cannot be found.
CThe success message ID is incorrect and causes NoSuchElementException.
DThe click() method is not supported on buttons.
Attempts:
2 left
💡 Hint

Check if the form or button is inside a frame or popup.