0
0
Selenium Pythontesting~20 mins

Submitting forms in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Form Submission 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 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()
AForm submitted
BNoSuchElementException
CElementNotInteractableException
DTimeoutException
Attempts:
2 left
💡 Hint
The form element is found and submit() is called directly.
assertion
intermediate
1: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
Aassert message == 'Success'
Bassert message is 'Success'
Cassert message.equals('Success')
Dassert message.contains('Success')
Attempts:
2 left
💡 Hint
Use Python string equality operator for exact match.
locator
advanced
1: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?
ABy.CLASS_NAME, 'submit-btn'
BBy.XPATH, '//input[@type="submit"]'
CBy.ID, 'submit'
DBy.CSS_SELECTOR, '#signup input[type="submit"]'
Attempts:
2 left
💡 Hint
Choose a locator that scopes inside the form and targets the submit input.
🔧 Debug
advanced
2: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()
AThe driver is not focused on the input element.
Bclick() can only be called on form elements, not input elements.
CThe input element is hidden (display:none), so click() cannot be called on it.
DThe input element has no value, causing the exception.
Attempts:
2 left
💡 Hint
Check if the element is visible and interactable before calling click().
framework
expert
3: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?
A
import pytest
from selenium import webdriver

@pytest.fixture
 def driver():
  driver = webdriver.Chrome()
  yield driver
  driver.quit()
B
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

@pytest.fixture
 def driver():
  options = Options()
  options.add_argument('--headless')
  driver = webdriver.Chrome(options=options)
  yield driver
  driver.quit()
C
import pytest
from selenium import webdriver

@pytest.fixture(scope='module')
 def driver():
  driver = webdriver.Chrome()
  yield driver
  driver.quit()
D
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

@pytest.fixture(scope='session')
 def driver():
  options = Options()
  options.add_argument('--headless')
  driver = webdriver.Chrome(options=options)
  yield driver
  driver.quit()
Attempts:
2 left
💡 Hint
Use headless mode and open/close browser for each test.