如何使用selenium webdriver(JAVA)从网格视图中选择特定记录
假设我想选择突出显示的记录in this snapshot。我怎么能这样做:
答案 0 :(得分:1)
您应该系统地将网格细分为多个部分,遍历每一行的单元格以使用唯一键找到匹配,然后选择该行。在这种情况下,唯一键是Employee Number列。
在Java中:
public void selectRow(String expEmpNo) {
// Get the grid
WebElement grid = driver.findElement(By.id("gpUsers"));
// Get all the rows
By locAllRows = By.xpath(".//*[contains(@class,'x-grid3-body')]//*[contains(@class,'x-grid3-row')]");
List<WebElement> allRows = grid.findElements(locAllRows);
// Loop through each row and compare actual emp. no. with expected emp. no.
for(WebElement row : allRows) {
// Emp No. is 4th column
By locEmpNo = By.xpath(".//*[@class='x-grid3-cell-inner x-grid3-col-4']");
// Get the Emp. No.
String actEmpNo = row.findElement(locEmpNo).getText();
// Compare actual vs expected
if(actEmpNo.equals(expEmpNo)) {
row.click(); // Select row
System.out.println("Selected row " + (allRows.indexOf(row) + 1) + " having Emp. No. " + expEmpNo)
break; // exit the for loop
}
}
}
答案 1 :(得分:-2)
我相信你需要这样的东西
WebElement element = driver.findElement(By.xpath("use the xpath here"));
Select oSelect = new Select(element);
oSelect.selectByVisibleText("enter the visible text you want to select");