0
WebElement element = driver
            .findElement(By
                    .xpath("html/body/div[7]/div[2]/div/div[2]/div[1]/div[2]/div/div/div/div[2]/div[1]/div[1]/div/div[2]/div/table/tr/td[1]/div[2]/div[2]/div/div[3]/div/div/div/div/div/div[1]/div[2]/div[9]/div[4]/span/a/div/div[3]/div[2]"));

    Actions builder = new Actions(driver);
    builder.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN)
            .sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

    System.out.println("right click should work now");

Hello guys!

I'm having trouble working on with the right click feature of Selenium WebDriver. As you can see above, I tried to execute that code (without error) but still WebDriver won't right click my desired page element.

I am currently writing test scripts for gmail file download. (Right Click + Save Link As)

I've tried Firefox profiling and it seems to work, but I think it's better if I will be able to test this way of downloading attachments.

Please advise.

Thanks a lot!

  • have you tried to use javascript for that? Check this post out http://stackoverflow.com/questions/433919/javascript-simulate-right-click-through-code – ingrid.e Apr 12 '16 at 11:02
  • a similar question http://stackoverflow.com/questions/2171589/how-can-you-do-right-click-using-selenium – ingrid.e Apr 12 '16 at 11:03
  • @ingrid.e - nope not yet. I've already checked that link. However it's really bothering for me that that set of codes work [here](https://www.youtube.com/watch?v=vZIOIAOYbmY) but not on mine. That's the answer I really want to know. Also, "action" is shorter and easier to understand rather than those answers they've given. (jsp solutions) – The Software Tester Apr 12 '16 at 11:23
  • There happens to be a ChromeDriver bug associated with this: https://bugs.chromium.org/p/chromedriver/issues/detail?id=535 Even though the issue details mention it as fixed, it isn't and has to be reopened. – Zeeshan S. Apr 12 '16 at 12:38
  • @Zeeshan - Bingo. That's the exact issue that I am encountering. The only difference is that I'm using FirefoxDriver, not ChromeDriver. I think they contain different sets of methods although both have the same objectives somehow right? But I think your response has given me new ideas. Thanks a lot, mate! – The Software Tester Apr 14 '16 at 08:37

0 Answers0