如何右键单击Selenium并选择所有UI网格行?

时间:2019-05-13 09:29:04

标签: c# selenium selenium-webdriver

我需要保持选中两个UI Grid行,以便显示右键单击自定义菜单。如果只选择了一行,则会显示一个不同的上下文菜单,因此我需要保持选中这两行。

任何想法如何做到这一点?

下面的代码是我尝试过的。这段代码很麻烦,即使选择了两行,也只能在一行上单击鼠标右键(实际上是取消选择了其中一行)

请参见下面的代码

class Program
{
    static void Main(string[] args)
    {
        IWebElement tableElement;

        String _address = "https://datatables.net/examples/api/select_row.html";

        IWebDriver _driver = new ChromeDriver();

        _driver.Navigate().GoToUrl(_address);
        tableElement = _driver.FindElement(By.Id("example"));

        Actions actions = new Actions(_driver);

        var noRows = _driver.FindElements(By.XPath("//table[@id='example']/tbody/tr"));

        for (int i = 0; i < 2; i++)
        {
            noRows[0].Click();  

            actions.KeyDown(Keys.Control).Click(noRows[1]).KeyUp(Keys.Control).Perform();

            actions.ContextClick(noRows).Perform();
        }
    }
}    

0 个答案:

没有答案