0
0
Selenium Javatesting~20 mins

Submitting forms in Selenium Java - 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 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");
AForm submitted (form is submitted successfully)
BNoSuchElementException at findElement(By.id("loginForm"))
CTimeoutException waiting for page load after submit
DElementNotInteractableException at form.submit()
Attempts:
2 left
💡 Hint
The form element is located by its id and submit() is called directly on it.
assertion
intermediate
1: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();
AassertFalse(currentUrl.contains("success"));
BassertEquals(currentUrl, "success");
CassertTrue(currentUrl.contains("success"));
DassertNull(currentUrl);
Attempts:
2 left
💡 Hint
Check if the URL includes the word 'success' anywhere.
locator
advanced
1: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?
ABy.xpath("//button[@type='submit']")
BBy.cssSelector("#signupForm button[type='submit']")
CBy.id("submit")
DBy.className("submit-btn")
Attempts:
2 left
💡 Hint
Choose a locator that scopes the button inside the specific form.
🔧 Debug
advanced
2: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();
AThe input element is not visible on the page
BThe driver has not navigated to any page yet
CThe locator By.name("username") is incorrect
Dsubmit() called on an input element instead of the form element
Attempts:
2 left
💡 Hint
submit() should be called on the form element, not on input fields.
framework
expert
2: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?
A
String oldUrl = driver.getCurrentUrl();
form.submit();
new WebDriverWait(driver, Duration.ofSeconds(10))
  .until(ExpectedConditions.not(ExpectedConditions.urlToBe(oldUrl)));
B
form.submit();
new WebDriverWait(driver, Duration.ofSeconds(10))
  .until(ExpectedConditions.urlContains("success"));
C
form.submit();
Thread.sleep(10000);
D
String oldUrl = driver.getCurrentUrl();
form.submit();
new WebDriverWait(driver, Duration.ofSeconds(10))
  .until(ExpectedConditions.urlToBe(oldUrl));
Attempts:
2 left
💡 Hint
Wait until the URL is no longer the old URL after submission.