对不起,我对 JAVA 还不够好。但以下逻辑将帮助您编写 Java 代码:
table = driver.find_element(:id, "table_id")
rows = table.find_elements(:tag_name, "tr")
len = rows.length
len.times do |i|
if table.find_element(:xpath, "//tr[#{i+1}]/td[2]/div").text.eql? "expected_text"
table.find_element(:xpath, "//tr[#{i+1}]/td[4]/div").click
end
end
这是一个 Java 代码(可能在语法上不正确)。试试看:
WebElement table = driver.findElement(By.id("table_id"));
// WebElement table = driver.findElement(By.xpath("//table[@class="jtable"]")); (for your case)
List<WebElement> rows = table.findElements(By.tagName("tr"));
for(int i=0; i<rows.length(); i++ ){
if(table.findElement(By.xpath("//tr[#{i+1}]/td[2]/div").getText == "expected_text"){
table.findElement(By.xpath("//tr[#{i+1}]/td[4]/div")).click();
}
}