The context click at current location action

Now that we have seen context click on a WebElement, it's time to explore the contextClick() method at the current mouse location. The API syntax for the contextClick() method is as follows:

public Actions contextClick()

As expected, the preceding method doesn't expect any input parameter and returns the Actions instance. Let's see the necessary modifications needed for the previous example to use this method. The following is the code refactored to achieve this:

@Test
public void shouldContextClickAtCurrentLocation() {

driver.get("http://guidebook.seleniumacademy.com/ContextClick.html");

WebElement contextMenu = driver.findElement(By.id("div-context"));
Actions actions = new Actions(driver);
actions.moveToElement(contextMenu)
.contextClick()
.click(driver.findElement(By.name("Item 4")))
.perform();
}

The preceding code first moves the cursor to the div-context WebElement and then context-clicks it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.185.180