How to right click in selenium | Selenium Forum
M
Posted on 09/11/2015
is it possible to simulate right clicking operation in selenium? if yes, can you please send me the code snippet please.

M
Replied on 09/11/2015

you will have to use javascript


function contextMenuClick(element){
var evt = element.ownerDocument.createEvent('MouseEvents');

var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE

evt.initMouseEvent('contextmenu', true, true,
element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
false, false, false, RIGHT_CLICK_BUTTON_CODE, null);

if (document.createEventObject){
// dispatch for IE
return element.fireEvent('onclick', evt)
}
else{
// dispatch for firefox + others
return !element.dispatchEvent(evt);
}
}