[英]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.