Selenium webdriver Selenium Webdriver-如何从网格视图中选择记录
如何使用SeleniumWebDriverJava从网格视图中选择特定记录Selenium webdriver Selenium Webdriver-如何从网格视图中选择记录,selenium-webdriver,Selenium Webdriver,如何使用SeleniumWebDriverJava从网格视图中选择特定记录 假设我想选择突出显示的记录。我该怎么做:我相信你需要这样的东西 WebElement element = driver.findElement(By.xpath("use the xpath here")); Select oSelect = new Select(element); oSelect.selectByVisibleText("enter the visible text you want to selec
假设我想选择突出显示的记录。我该怎么做:我相信你需要这样的东西
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");
您应该系统地将网格分解为多个部分,使用唯一键循环每一行的单元格以找到匹配项,然后选择该行。在这种情况下,唯一键是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
}
}
}
感谢您的反馈,但据我所知,选择对象用于处理下拉列表,而不是网格视图。不管怎样,我明天会试试,并为你提供反馈,请原谅我的误解。因此,我认为使用element.click是谨慎的;