Context menu items are custom additions that appear in the right-click menu.
- Context menu click: Right-click action in the Selenium web driver can be done using the Actions class. The pre-defined method provided by the Actions class is used to perform the right-click operation.
- Alert handling: Alert is a small message box that displays an on-screen notification to give the user some kind of information or ask for permission to perform a certain kind of operation. It may be also used for warning purposes.
Navigate to https://www.qafeast.com/demo, and click the context menu tab.
Press F12 on the keyboard and inspect the context menu

Python:
Context menu click:
actionChains = ActionChains(driver)
elementLocator = driver.find_element_by_id("hot-spot")
actionChains.context_click(elementLocator).perform()
Accept the Alert:
alert = driver.switch_to.alert
alert.accept()
Cancel the Alert:
alert = driver.switch_to_alert()
alert.dismiss()
To get the text in the Alert:
alert = driver.switch_to_alert()
print(alert.text)
C#:
Context menu click:
IWebElement element = driver.FindElement(By.Id("hot-spot"));
Actions builder = new Actions(driver);
builder.ContextClick(element).Build().Perform();
Accept the Alert:
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
Cancel the Alert:
IAlert alert = driver.SwitchTo().Alert();
alert.Dismiss();
To get the text in the Alert:
IAlert alert = driver.SwitchTo().Alert();
Console.Write(alert.Text);
Java code:
Context menu click:
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("hot-spot"));
actions.contextClick(elementLocator).perform();
Accept the Alert:
Alert alert = driver.switchTo().alert();
alert.accept();
Cancel the Alert:
Alert alert = driver.switchTo().alert();
alert.dismiss();
To get the text in the Alert:
Alert alert = driver.switchTo().alert();
alert.getText();