Assuming the page has no element with ID "submit".
medium
A. Throws ElementNotInteractableException at sendKeys line.
B. No error; code runs fine.
C. Throws NoSuchElementException at finding "submit" element.
D. Throws StaleElementReferenceException at click line.
Solution
Step 1: Check element existence for each findElement
The element with ID "email" exists, so sendKeys works fine.
Step 2: Analyze finding "submit" element
Since "submit" ID does not exist, findElement(By.id("submit")) throws NoSuchElementException.
Final Answer:
Throws NoSuchElementException at finding "submit" element. -> Option C
Quick Check:
Missing ID causes NoSuchElementException [OK]
Hint: Missing ID in findElement causes NoSuchElementException [OK]
Common Mistakes:
Assuming sendKeys fails if element missing later
Confusing exceptions thrown at different lines
Expecting click() to throw error instead of findElement
5. You want to fill a form field with ID "userEmail" and then click a button with ID "submitBtn". Which code snippet correctly handles the possibility that the button might not be present, avoiding test failure?
hard
A. driver.findElement(By.id("userEmail")).sendKeys("user@example.com");
try {
driver.findElement(By.id("submitBtn")).click();
} catch (NoSuchElementException e) {
System.out.println("Button not found, skipping click.");
}