[英]How to select multiple rows at different place in a table using Selenium Webdriver
I am trying below code to fetch the table rows, but I need to select the rows which are at different place in a table.我正在尝试使用下面的代码来获取表格行,但我需要选择表格中不同位置的行。
@Test public void testRowSelectionUsingControlKey() { List tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr")); for(int i=0; i<tableRows.size(); i++){ System.out.println(tableRows.get(i).getText()); }
To select table rows at different position in a table you need to use Action Class and then you can use the CTRL buttons to select the elements that you want. 要在表中的不同位置选择表行,您需要使用Action Class,然后可以使用CTRL按钮选择所需的元素。 Lets say I need to select 1st and 4th row of a table, I'll do something like below:
让我们说我需要选择一个表的第一行和第四行,我会做如下的事情:
For Example: 例如:
public void testRowSelectionUsingControlKey() { List tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr")); Actions builder = new Actions(driver); builder.click(tableRows.get(1)).keyDown(Keys.CONTROL).click(tableRows.get(4)).keyUp(Keys.CONTROL).build().perform(); }
Above example is working perfectly with Selenium and C# with minor modifications below: 以上示例与Selenium和C#完美配合,下面稍作修改:
public void testRowSelectionUsingControlKey() {
var tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr"));
Actions builder = new Actions(driver);
builder.Click(tableRows[1]).keyDown(Keys.Control).Click(tableRows[4]).keyUp(Keys.Control).Build().Perform();
}
@Test
public void testRowSelectionUsingControlKey() {
List tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr"));
for(int i=0; i<tableRows.size(); i++){
System.out.println(tableRows.get(i).getText());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.