Search code examples
seleniumtestingautomated-testsright-clickselenium3

Right click without Actions in Selenium 3.x in Firefox browser


How to right click an element without using Actions object. I get exception while using Actions in Selenium3 in FireFox with GeckoDriver. I have used the following code to set the GeckoDriver property.

System.setProperty("webdriver.gecko.driver", new File("lib/geckodriver").getAbsolutePath());

Solution

  • Try using Robot class to right click on WebElement:

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_ENTER);
    

    and to set the system properties for gecko driver you can use the below line :

    System.setProperty("webdriver.gecko.driver", path of your geckodriver.exe");