[英]How to select multiple rows at different place in a table using Selenium Webdriver
我正在尝试使用下面的代码来获取表格行,但我需要选择表格中不同位置的行。
@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()); }
要在表中的不同位置选择表行,您需要使用Action Class,然后可以使用CTRL按钮选择所需的元素。 让我们说我需要选择一个表的第一行和第四行,我会做如下的事情:
例如:
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(); }
以上示例与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.