我已在下面的代码中编写了使用selenium webdriver选择前5行的代码。但它没有用。
public void testRowSelectionUsingControlKey() {
List tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr"));
Actions builder = new Actions(driver);
builder.click(tableRows.get(0)).keyDown(Keys.CONTROL).click(tableRows.get(1)).keyDown(Keys.CONTROL).click(tableRows.get(2)).keyDown(Keys.CONTROL).click(tableRows.get(3)).keyDown(Keys.CONTROL).click(tableRows.get(4)).keyUp(Keys.CONTROL).build().perform();
}
答案 0 :(得分:0)
每次从表格中选择一行时,您都不需要调用方法keyDown(Keys.CONTROL)
。在选择所有行之前尝试拨打keyUp(Keys.CONTROL)
,然后拨打public void testRowSelectionUsingControlKey() {
List tableRows = driver.findElements(By.xpath("//table[@class='iceDatTbl']/tbody/tr"));
Actions builder = new Actions(driver);
builder.keyDown(Keys.CONTROL)
.click(tableRows.get(0))
.click(tableRows.get(1))
.click(tableRows.get(2))
.click(tableRows.get(3))
.click(tableRows.get(4))
.keyUp(Keys.CONTROL).build().perform();
}
。
theObjects.Where(g => idList.Contains(g.id)).ForEach(g => g.selected = true);