Challenge - 5 Problems
Form Submission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Python code snippet?
Consider the following Selenium code that tries to submit a form. What will be printed after execution?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') driver = webdriver.Chrome(options=options) driver.get('data:text/html,<form id="login"><input type="text" name="user"><input type="submit" value="Send"></form>') form = driver.find_element(By.ID, 'login') form.submit() print('Form submitted') driver.quit()
Attempts:
2 left
💡 Hint
The form element is found and submit() is called directly.
✗ Incorrect
The code finds the form by ID and calls submit() on it. This triggers form submission without errors, so 'Form submitted' is printed.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies form submission success?
After submitting a form, the page shows a message with id 'success-msg'. Which assertion correctly checks that the message text is 'Success'?
Selenium Python
from selenium.webdriver.common.by import By message = driver.find_element(By.ID, 'success-msg').text
Attempts:
2 left
💡 Hint
Use Python string equality operator for exact match.
✗ Incorrect
In Python, '==' compares string values correctly. 'is' checks identity, which is not reliable for strings. 'equals' and 'contains' are not valid Python string methods.
❓ locator
advanced1:30remaining
Which locator is best to find the submit button inside a form with id 'signup'?
You want to locate the submit button inside the form with id 'signup'. Which locator is the most precise and reliable?
Attempts:
2 left
💡 Hint
Choose a locator that scopes inside the form and targets the submit input.
✗ Incorrect
Option D uses CSS selector scoped inside the form with id 'signup' and targets input with type submit, making it precise. Option D is too broad and may find other submit inputs. Options A and D rely on attributes that may not exist.
🔧 Debug
advanced2:00remaining
Why does this Selenium form submission code raise ElementNotInteractableException?
Given this code snippet, why does calling click() on the element raise ElementNotInteractableException?
Code:
email_input = driver.find_element(By.NAME, 'email')
email_input.click()
Attempts:
2 left
💡 Hint
Check if the element is visible and interactable before calling click().
✗ Incorrect
The click() method requires the element to be visible and interactable. Here, the input is hidden with display:none, so Selenium raises ElementNotInteractableException.
❓ framework
expert3:00remaining
Which pytest fixture setup is best for testing form submission with Selenium?
You want to write pytest tests that submit forms using Selenium WebDriver. Which fixture setup ensures the browser opens before each test and closes after, with headless mode enabled?
Attempts:
2 left
💡 Hint
Use headless mode and open/close browser for each test.
✗ Incorrect
Option B uses headless mode and a fixture with default function scope, so browser opens before each test and closes after. Options B and D miss headless mode or have broader scope. Option B misses headless mode.