power_settings_new
How may I click on a link using context menu so that the page is opened in a new tab?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes

Performing context menu click is little tricky part here. You need to use Action classes here.

 

Open in new window.

WebElement link = getMyDriver().findElement(By.id("yourElementIdHere"));
Actions actions= new Actions(getMyDriver());
actions.keyDown(Keys.SHIFT).click(link).keyUp(Keys.SHIFT).build().perform();
 
Open in new tab.
 
WebElement link = getMyDriver().findElement(By.id("MyIdHere"));
Actions actions= new Actions(getMyDriver());
actions.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).click(link).keyUp(Keys.CONTROL).keyUp(Keys.SHIFT).build().perform();
 
Hope above code helps.
add
...