0
votes

I am trying to use Selenium Webdriver to right click on a page, and navigate the context menu. This script should open a right click menu, and navigate Up 2 options, then select with the Return key...

driver.Navigate().GoToUrl("http://www.google.com");
//Google search bar
IWebElement tb = driver.FindElement(By.Id("lst-ib"));
Actions action = new Actions(driver);
//Right Clicks outside of the search bar.
action.MoveToElement(tb, -5, -5).ContextClick().Perform();
action.SendKeys(Keys.Up).SendKeys(Keys.Up).SendKeys(Keys.Return).Perform();

The right click executes as it should (outside of the search bar), but after that, there is no evidence of the Up arrow being pressed, and nothing is selected with the Return key. The menu options should highlight as they scroll through.

I am using the latest version of ChromeDriver 2.30, and Chrome 59.0.3071.109

3
This is a known issue in ChromeDriver, I suggest using FirefoxDriver instead: bugs.chromium.org/p/chromedriver/issues/detail?id=1003budi
Thank you, I believe this is the case, as I'm having trouble completing other actions. Using a modifier key (ctrl+m) as a shortcut to open the extension would be easier than using the context menu, but that isn't working either... I guess I'll try firefox and wait for a fix.dsidler

3 Answers

0
votes

If your application only runs on Windows, you may use System.Windows.Forms.SendKey.

action.MoveToElement(tb, -5, -5).ContextClick().Perform();
System.Windows.Forms.SendKeys.SendWait("{UP}");
System.Windows.Forms.SendKeys.SendWait("{UP}");
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
0
votes

If it is user designed context menu . The context menu itself would be having the locator

       `WebElement element =driver.findElement(By.xpath("your xpath"));

        Actions action = new Actions(driver);
        action.contextClick(selectedCell).build().perform();
        WebElement copyContext = driver.findElement(By.xpath("xpath of the right context column"));

    if (copyContext .isEnabled())
    {
        copyContext .click();
        log.info("Right context menu COPY CONTENT clicked.");
    }

`

0
votes

This chromedriver bug has been unattended since 2015. I resorted to PyAutoGui for controlling dialog boxes.

http://pyautogui.readthedocs.org/