简体   繁体   English

如何在不使用C#按住CTRL键的情况下在UI网格中选择多行?

[英]How to select multiple rows in a UI grid without holding CTRL key using C#?

I have a table written in Angular and when I write the code below, I can't click to select multiple rows (it works for the table example below). 我有一个用Angular编写的表,当我编写下面的代码时,我无法单击以选择多行(它适用于下面的表示例)。 For my table at work, it only allows me to select one row at a time so looping is not working. 对于我的工作表,它只允许我一次选择一行,因此循环不起作用。 My question is how to select all rows in a UI grid table? 我的问题是如何选择UI网格表中的所有行?

I've tried writing a loop to click until the last row is reached, but for the Angular site at work, it only allows one row to be selected at a time. 我尝试编写一个循环以单击直到到达最后一行,但是对于正在工作的Angular站点,它一次只能选择一行。 I can't use the CTRL key as it needs to run without user interaction. 我不能使用CTRL键,因为它需要在没有用户交互的情况下运行。 I've looked into the Actions class for selenium but I can't get it to work. 我已经研究了硒类的Actions类,但无法正常使用。

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 < noRows.Count; i++)
        {
            noRows[i].Click();
        }

        Console.Write("ALl lines seleected");
    }
  }
}

在此处输入图片说明

I worked it out by adding this line 我通过添加这一行来解决

actions.KeyDown(Keys.Control).Click(gridTotal[1]).KeyUp(Keys.Control).Build().Perform(); actions.KeyDown(Keys.Control).Click(gridTotal [1])。KeyUp(Keys.Control).Build()。Perform();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不按住Ctrl键的情况下在WPF DataGrid中选择多行? - How select multiple rows in WPF DataGrid without holding Ctrl Key? c# - 如何在不按CTRL键的情况下多选DataGridView行? - How to multiselect DataGridView rows without pressing CTRL key in c#? 如何在datagridview C#中使用shift和Ctrl键选择多行 - how select multiple row using shift and Ctrl key in datagridview C# 在WPF中配置ListBox,这样我就可以在不保持CTRL键的情况下选择多个项目 - Configure ListBox in WPF so that I will be possible to select multiple items without holding CTRL key 使用C#禁用没有注册表的Ctrl或Alt键 - Disable Ctrl or Alt key without registry using c# 使用Ctrl + A键选择网格中的行时如何获取选定的索引 - How to get selected index when used to Ctrl+A key to select rows in grid 使用C#测试Ctrl键是否已关闭 - Test if the Ctrl key is down using C# 如何在C#中不使用openfileDialog的情况下选择多个文件 - how to select multiple files without using openfileDialog in c# 如何使用 C# 在 Unity 中通过按住键盘上的一个键(例如:&#39;W&#39; 键)使对象移动? - How to make an object moves by holding a key on the keyboard down (ex: 'W' key) in Unity using C#? 如何在不按Ctrl键的情况下选择datagridview的多个单元格? - How do i select multiple cells of datagridview without pressing Ctrl key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM