Challenge - 5 Problems
Context Click Mastery
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 performs a context click on a web element. What will be printed if the context click is successful and the alert text is "Right click detected"?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com/context-menu"); WebElement box = driver.findElement(By.id("box")); Actions actions = new Actions(driver); actions.contextClick(box).perform(); Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); System.out.println(alertText); alert.accept(); driver.quit();
Attempts:
2 left
💡 Hint
Think about what happens after a context click triggers an alert.
✗ Incorrect
The code performs a right click on the element with id 'box'. This triggers a JavaScript alert with the text 'Right click detected'. The alert text is printed, then the alert is accepted and the browser closes.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the context click triggered the expected alert?
You want to verify that after performing a context click on an element, an alert with text "Context menu opened" appears. Which assertion is correct in Java using TestNG?
Selenium Java
WebElement element = driver.findElement(By.cssSelector(".menu"));
Actions actions = new Actions(driver);
actions.contextClick(element).perform();
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();Attempts:
2 left
💡 Hint
You want to check exact match of alert text.
✗ Incorrect
Option A checks that the alert text exactly matches the expected string, which is the most precise verification.
🔧 Debug
advanced2:00remaining
Why does this context click code throw ElementNotInteractableException?
Given this code snippet, why does it throw ElementNotInteractableException when performing context click?
Selenium Java
WebElement hiddenElement = driver.findElement(By.id("hidden"));
Actions actions = new Actions(driver);
actions.contextClick(hiddenElement).perform();Attempts:
2 left
💡 Hint
Think about element visibility and interactability.
✗ Incorrect
ElementNotInteractableException occurs when the element is present in DOM but not visible or disabled, so Selenium cannot interact with it.
❓ framework
advanced2:00remaining
Which Selenium Java code snippet correctly performs a context click and verifies the context menu is displayed?
Select the code snippet that performs a right click on an element with id "menu" and asserts that the context menu with id "context-menu" is visible afterwards.
Attempts:
2 left
💡 Hint
Remember to call perform() to execute the action.
✗ Incorrect
Option D correctly performs contextClick and calls perform() to execute the action. Then it asserts the context menu is visible. Option D misses perform(), so action is not executed.
🧠 Conceptual
expert2:00remaining
What is the main reason to use context click in Selenium tests?
Why would a tester use context click (right click) in Selenium automated tests?
Attempts:
2 left
💡 Hint
Think about what right click does in normal user behavior.
✗ Incorrect
Context click simulates the user right-clicking on an element, which usually opens a context menu or triggers special options. This is important to test those UI features.