Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 2 right-click

I am using Selenium 2 (Web Driver) under Linux with a FireFoxDriver.

I am not able to perform a right click on a WebElement or on another possition using coordinates. I also cannot move the mouse pointer.

I have tried to use the "Actions" object:

Actions actions = new Actions(ffDriver);
WebElement we = ffDriver.findElement(By.linkText("WhatEver"))
actions.contextClick(we).build().perform();

I also have tried to use the "Mouse" object:

Mouse mouse = ((HasInputDevices)ffDriver).getMouse();
mouse.contextClick(we.getCoordinates());

These codes don't fail but they don't do anything.

However, if I perform a regular click in the two examples above, it works as expected.

Do anybody know what is the problem with this?

Thank you.

like image 711
Angel Romero Avatar asked Nov 04 '11 09:11

Angel Romero


1 Answers

Finally I understood the issue.

On Selenium 2, the "contextClick" function over a web element does not simulate a right click into that element, it just activate the "onContextMenu()" event placed in the HTML code of the element.

So, if you want to access to that kind of context menus, it should be handled on the HTML code.

like image 89
Angel Romero Avatar answered Oct 18 '22 07:10

Angel Romero