【问题标题】:Selenium Webdriver Actions are not working with context menu (right click)Selenium Webdriver 操作不适用于上下文菜单(右键单击)
【发布时间】:2017-06-21 17:38:30
【问题描述】:

我正在尝试使用 Selenium Webdriver 右键单击​​页面,然后导航上下文菜单。该脚本应打开一个右键菜单,并导航向上 2 个选项,然后使用 Return 键选择...

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();

按原样执行右键单击(在搜索栏之外),但此后,没有任何证据表明按下了向上箭头,并且没有使用 Return 键选择任何内容。菜单选项应在滚动时突出显示。

我正在使用最新版本的 ChromeDriver 2.30 和 Chrome 59.0.3071.109

【问题讨论】:

  • 这是 ChromeDriver 中的一个已知问题,我建议改用 FirefoxDriver:bugs.chromium.org/p/chromedriver/issues/detail?id=1003
  • 谢谢,我相信是这种情况,因为我无法完成其他操作。使用修饰键 (ctrl+m) 作为打开扩展程序的快捷方式比使用上下文菜单更容易,但这也不起作用……我想我会尝试使用 firefox 并等待修复。跨度>

标签: selenium selenium-webdriver


【解决方案1】:

如果您的应用程序仅在 Windows 上运行,您可以使用 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}");

【讨论】:

    【解决方案2】:

    如果是用户设计的上下文菜单。上下文菜单本身将具有定位器

           `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.");
        }
    

    `

    【讨论】:

      【解决方案3】:

      此 chromedriver 错误自 2015 年以来一直无人关注。 我使用 PyAutoGui 来控制对话框。

      http://pyautogui.readthedocs.org/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-30
        相关资源
        最近更新 更多