我正在尝试使用下面的代码来获取表格行,但我需要选择表格中不同位置的行。
@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 按钮选择您想要的元素。 假设我需要选择表格的第 1 行和第 4 行,我将执行如下操作:
例如:
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(); }
关于java - 如何使用 Selenium Webdriver 选择表中不同位置的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18632415/