Working with context menus
A context menu (also known as a shortcut, a popup, or a pop-up menu) is a menu displayed on a web page that appears when a user performs a right-click mouse operation. For example, here is a jQuery contextMenu
plug-in from http://bit.ly/1CAV05I, which displays the editing menu when a user performs a right-click operation.
The Selenium WebDriver Actions
class provides the contextClick()
method to perform a right-click operation. In this recipe, we will explore how to automate interaction on a context menu.
How to do it...
Let's implement a test that will open a context menu and select one of the menu options using the Actions
class:
@Test public void testContextMenu() { WebElement clickMeElement = driver.findElement(By.cssSelector("div.context-menu-one.box.menu-1")); WebElement editMenuItem = driver.findElement(By.cssSelector("li.context-menu-item.icon-edit")); Actions builder = new Actions(driver); builder.contextClick(clickMeElement) .moveToElement(editMenuItem...