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 Java code snippet?
Consider the following Selenium Java code that attempts to submit a form. What will be the result of executing this code?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com/login"); WebElement form = driver.findElement(By.id("loginForm")); form.submit(); System.out.println("Form submitted");
Attempts:
2 left
💡 Hint
The form element is located by its id and submit() is called directly on it.
✗ Incorrect
The code locates the form element by its id and calls submit() on it, which triggers form submission. If the element exists and is a form, the submission succeeds and the print statement executes.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies form submission success?
After submitting a form, you want to verify that the page URL contains "success". Which assertion is correct in JUnit 5?
Selenium Java
String currentUrl = driver.getCurrentUrl();
Attempts:
2 left
💡 Hint
Check if the URL includes the word 'success' anywhere.
✗ Incorrect
assertTrue(currentUrl.contains("success")) correctly checks that the URL contains the substring 'success'. Other options either check equality or wrong conditions.
❓ locator
advanced1:30remaining
Which locator is best to find the submit button inside a form with id 'signupForm'?
You want to locate the submit button inside the form with id 'signupForm'. Which locator is the most precise and reliable?
Attempts:
2 left
💡 Hint
Choose a locator that scopes the button inside the specific form.
✗ Incorrect
Option B uses a CSS selector that finds a button with type 'submit' inside the form with id 'signupForm', making it precise and less prone to errors than global selectors.
🔧 Debug
advanced2:00remaining
Why does this Selenium Java code fail to submit the form?
The following code throws an ElementNotInteractableException when calling submit(). What is the likely cause?
Selenium Java
WebElement input = driver.findElement(By.name("username")); input.submit();
Attempts:
2 left
💡 Hint
submit() should be called on the form element, not on input fields.
✗ Incorrect
Calling submit() on an input element causes ElementNotInteractableException because only form elements support submit(). The fix is to locate the form and call submit() on it.
❓ framework
expert2:30remaining
Which Selenium Java code snippet correctly waits for form submission to complete by waiting for URL change?
You want to submit a form and wait until the URL changes to confirm submission. Which code snippet correctly implements this using WebDriverWait?
Attempts:
2 left
💡 Hint
Wait until the URL is no longer the old URL after submission.
✗ Incorrect
Option A stores the old URL, submits the form, then waits until the URL is different from the old one, confirming navigation after submission. Option A waits for a specific substring which may not always be present. Option A uses fixed sleep which is unreliable. Option A waits for the URL to remain the same, which is incorrect.