我需要帮助将Selenium与动态表一起使用。
我需要点击状态等于"活动"的最后一个帐户在图像中出现了示例。
动态表
我正在尝试使用下一个代码:
WebElement lastCredit = driver.findElement(By.xpath("(//table[@class='tableinfo']/tbody/tr[last()]/td[3]/a and contains(text(), 'ACTIVE'") );
lastCredit.sendKeys(Keys.ENTER);
我无法单击该帐户,并且程序失败。
我正在尝试使用 2 用于:
WebElement rows = driver.findElement(By.xpath("(//table[@class='tableinfo']/tbody/tr"));
List<WebElement> columns = (List<WebElement>) driver.findElement(By.xpath("(//table[@class='tableinfo']/tbody/tr[1]/td"));
String[] array = new String[4];
for(int i = 0; i <= rows.length; i = i ++)
{
for(int j = 0; j <= columns.length; j = j ++)
{
array[j] = driver.findElement(By.xpath("(//table[@class='tableinfo']/tbody/tr[i]/td[j]/a")).getAttribute("value");
}
if (array[4] == “ACTIVE”) and (array[4].last()); {
array.get(4).click();
}
}
请帮助我。
无论图像如何,如果您的要求是单击最后一个活动状态,请尝试以下简单代码段
List<WebElement> activeColumns = driver.findElements(By.xpath("//td[text()='ACTIVE']"));
activeColumns.get(activeColumns.size()-1).click();