Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用SeleniumWebDriver在表中的不同位置选择多行_Java_Selenium Webdriver - Fatal编程技术网

Java 如何使用SeleniumWebDriver在表中的不同位置选择多行

Java 如何使用SeleniumWebDriver在表中的不同位置选择多行,java,selenium-webdriver,Java,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++){ Syste

我试图在下面的代码中获取表行,但我需要选择表中不同位置的行

@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类,然后可以使用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();
}

这就是你想做的吗?是的,这就是我想要的。谢谢:你的代码会打印所有的行,对吗?你只想要一些?您希望根据哪些标准选择它们?还是我读错了?我只想选择表格中不同位置的元素。。。不要与for循环混淆,它只是用来打印行的,下面提供的解决方案解决了我的问题。。。。无论如何,谢谢。我有类似的案例,但我想从1到5行中选择1、2、3、4、5行。我怎么做?我已经用过钥匙了。换一种方式吗?public void testRowSelectionUsingControlKey{var tableRows=driver.findElementsBy.xpath//table[@class='iceDatTbl']/tbody/tr;Actions builder=new Actions驱动程序;builder.ClicktableRows[1]。keyDownKeys.Shift.ClicktableRows[4]。keyUpKeys.Control.Build.Perform;}