Right click on default browser context menu to do copy/paste

1,104 views
Skip to first unread message

Janette Schreider

unread,
Apr 19, 2015, 9:21:05 AM4/19/15
to seleniu...@googlegroups.com
I cannot seem to figure out or locate information on how to right click on the default browser menu to do copy and paste.

I am using Selenium WebDriver on Chrome and C#.  I can right click the context menu using Actions but I cannot figure out how to select the Copy or Paste options as these 
are not in the DOM and I cannot figure out what the locators would be for them.

Has anybody been able to do this?

Thanks.

brandon garlock

unread,
Apr 19, 2015, 1:32:38 PM4/19/15
to seleniu...@googlegroups.com
The right click menu is not part of the DOM. It is Operating System and Browser implementation specific.

I have to highly discourage this path. I am having a tough time figuring out why you would not want to get the info you are trying to copy directly using Selenium.

Pavan Turlapati

unread,
Apr 20, 2015, 2:38:13 AM4/20/15
to seleniu...@googlegroups.com
Can you even please tell what exactly are you trying to copy and paste?

Sidenote:
1. For selenium you can use Keyboard commands
2. For C# you can access clipboard.

Janette Schreider

unread,
Oct 28, 2015, 5:54:44 PM10/28/15
to Selenium Users
I gave up on this for a long time and now am back trying it again.

I am writing automation tests that exactly mimic manual actions by user.

One requirement I have is that a user can click on an input textbox, use the right context menu and arrow down to "Select All",  right click again and select "Copy" from the context menu and then go to a different input textbox and right click to select "Paste" from the context menu.

I do not want to use clipboard or keyboard commands as that is not the action required in my test.

I can use Actions and use ContextClick(element) to get the context menu to appear, but any actions I do after that - such as SendKeys(Arrow.Right) - are performed on the textbox,  not the Context Menu.  How do I keep the focus in the ContextMenu so that I can arrow to an option and select it?

Thank you.

PeterJeffreyGale

unread,
Oct 29, 2015, 5:10:04 AM10/29/15
to Selenium Users
While automating the context menu should be possible, I am curious why you want to do this at all in this case.

The Select All, copy and Paste are part of the browser's own functionality, I believe, and not part of a web page's code, so if it doesn't work, your devs can't fix it (can they?), so it would be pointless you running tests for it.

And even one browser doesn't provide the option you want to use, or it doesn't work properly fro some reason, a user would be able to use other means to copy and paste the data. 

arupa...@multiplan.com

unread,
May 16, 2016, 10:22:15 AM5/16/16
to Selenium Users
Well,  in case of writing automation script I need to access the browser's default context menu for a particular feature developed by devs. As long as that user defined context menu is available there is no problem. but I also need to test other side that this user defined context menu is not available in other page or in same page but other state e.g when the user's case is open the user defined context menu should be available but when it is closed it won't be. 

To verify that unavailability I need to right click targeting the specific row, As the user defined menu is not available web driver opens the browser default context menu. I have no problem in opening the default one but I need to close them so the driver can identify other element in that page. I have tried in different way but I gave up. I am not able to close it. Even when I navigate the driver from one web page to other web page it is still there. 

In addition some times we need to verify that some fields like account number, password input fields where organization might not want their users to be able to copy or paste any thing. if developers can disable that facility in the browser then we need to write script in that way unless management decides to exempt that feature testing in automation. 

PeterJeffreyGale

unread,
May 16, 2016, 4:49:54 PM5/16/16
to Selenium Users
I believe my comments were in respect to Janette's specific question, Arupa.Only Janette can really answer that.

If you need help with what you are trying to achieve, please start a new thread.

Louis Duran

unread,
Jan 19, 2017, 10:51:38 PM1/19/17
to Selenium Users
Janette,

Have you tried just navigating the menu with the keyboard commands? I suspect it won't work or may be browser dependent but it's worth a try. You might do it like this:

actions.sendKeys(Key.ARROW_DOWN).sendKeys(Key.RETURN).perform();

this SHOULD select the first item in the list and select it with RETURN. Add more ARROW_DOWN commands to get items further down in the list.
I am able to get as far as bringing up the context menu, but I can't make the selections.

I know your post was a long time ago... sorry.
Reply all
Reply to author
Forward
0 new messages