Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
how to right click on Selenium WebDriver?

Open 4 Answers 67 Views
0 4
I am working on a scenario where I have to right click on the webpage and perform the operation. How do I do that using Selenium?

4 Answers

2
2

You can use below code to right click in Seleium Webdriver:

Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
action.contextClick(element).perform();

Many professional software testing companies use this simple trick and I hope this will help you too.

answered by (570 points)
edited by
1
1
You can use contextClick from actions classes.

Actions action= new Actions(driver);
action.contextClick(productLink).build().perform();

Hope that helps!
answered by (859 points)
1
1
Hi user,

Let me explain the code here.....

If you want to right click on any element then selenium doesn't provide any direct method for that. We need to use Actions class provided by WebDriver. The Actions class provided by Selenium Webdriver is used to generate complex user gestures including right click, double click, drag and drop etc.
Here is the code:-

Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
action.contextClick(element).perform();

Here, we are instantiating an object of Actions class. After that, we pass the WebElement to be right clicked as parameter to the contestClick() method present in the Actions class. Then, we call the perform() method to perform the generated action.

Hope this will help you...
answered by (54 points)
0
0

1. Using Robot Class :

Robot r= new Robot();

 r.mousePress(InputEvent.BUTTON1_DOWN_MASK); // press right click

r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // release lright click

2.  Actions action = new Actions(d);

WebElement e1 = driver.findElement(By.id("ID"));
action.contextClick(e1).build().perform();

 

answered by

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.
...