0
0
Selenium Javatesting~20 mins

Click actions in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Click Actions 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 click action code?
Consider the following Selenium Java code snippet that tries to click a button. What will be the output or result of this test execution?
Selenium Java
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
WebElement button = driver.findElement(By.id("submitBtn"));
button.click();
System.out.println("Clicked successfully");
ATimeoutException waiting for page load
BNoSuchElementException at findElement
CClicked successfully
DElementNotInteractableException at click
Attempts:
2 left
💡 Hint
Assume the element with id 'submitBtn' exists and is visible on the page.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a button was clicked?
After clicking a button, you want to assert that a confirmation message with id 'confirmMsg' is displayed. Which assertion is correct in Selenium Java?
Selenium Java
WebElement confirmMsg = driver.findElement(By.id("confirmMsg"));
AassertTrue(confirmMsg.isDisplayed());
BassertEquals(confirmMsg.getText(), "");
CassertFalse(confirmMsg.isDisplayed());
DassertNull(confirmMsg);
Attempts:
2 left
💡 Hint
The confirmation message should be visible after clicking.
locator
advanced
2:00remaining
Which locator is best to click a button with text 'Submit'?
You want to click a button that has the visible text 'Submit'. Which locator is the best practice in Selenium Java?
ABy.id("submit")
BBy.xpath("//button[text()='Submit']")
CBy.cssSelector("button:contains('Submit')")
DBy.className("submit-btn")
Attempts:
2 left
💡 Hint
The button has no id or class, only visible text.
🔧 Debug
advanced
2:00remaining
Why does this click action throw ElementNotInteractableException?
Given this code snippet, why does the click fail with ElementNotInteractableException? WebElement button = driver.findElement(By.id("hiddenBtn")); button.click();
AThe button is present but not visible or enabled on the page
BThe driver has not navigated to any page yet
CThe locator By.id("hiddenBtn") is incorrect
DThe click() method is deprecated and cannot be used
Attempts:
2 left
💡 Hint
ElementNotInteractableException means the element cannot be clicked because of its state.
framework
expert
2:00remaining
Which Selenium Java code snippet correctly waits and clicks a button?
You want to wait up to 10 seconds for a button with id 'loadBtn' to be clickable, then click it. Which code snippet is correct?
Adriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.findElement(By.id("loadBtn")).click();
Bdriver.findElement(By.id("loadBtn")).click(); Thread.sleep(10000);
Cnew WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("loadBtn"))).click();
Dnew WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("loadBtn"))).click();
Attempts:
2 left
💡 Hint
Use explicit wait for clickable condition before clicking.