Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
275 views
in Selenium by The go-to Tester (391 points)
How may I click on a link using context menu so that the page is opened in a new tab?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

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.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...