1

I want to perform right click using web driver in Chrome ? Please Suggest

Below is the code I am using:-

Actions actions = new Actions(driver);
Action action=actions.contextClick(element).build(); 
action.perform(); 
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • I am trying below code but getting error Actions actions = new Actions(driver); Action action=actions. context Click (element).build(); action.perform(); getting error as no such code – Srikrishna Nadagouda Sep 09 '15 at 11:48
  • 1
    add your comment in question – Shravan Yadav Sep 09 '15 at 12:16
  • That will perform a right click, what is your actual problem. Do you want to select something from the context menu and you can't? Do you want to take a screenshot of the context menu? – Ardesco Sep 10 '15 at 10:28

3 Answers3

2

This works for me in c#

Actions actions = new Actions(Driver.Instance);
actions.ContextClick(element).Perform();
1
Actions action= new Actions(driver);
action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();

if you want to select the first option from the right click drop down.

Rohit
  • 370
  • 2
  • 11
  • Please don't post link only answers. Please post the relevant part of the answer. If it's a duplicate, please mark it as such. – JeffC Sep 09 '15 at 21:10
0

Try the below code:

 Actions act = new Actions(driver); // where driver is WebDriver type

 act.moveToElement(webElement).perform();

 act.contextClick().perform();
giri-sh
  • 6,934
  • 2
  • 25
  • 50
Ram Pasala
  • 4,931
  • 3
  • 16
  • 26