如何通过使用Java在selenium中显示其可见文本来列出网页中可用的所有复选框?
答案 0 :(得分:1)
对于该网站,这应该
List<WebElement> checkboxes = driver.findElements(By.cssSelector("input[type=checkbox]"));
JavascriptExecutor js = (JavascriptExecutor) driver;
if (checkboxes.isEmpty()) {
System.out.println("No Checkbox present in the page");
} else {
for (WebElement checkbox : checkboxes) {
if (checkbox.isDisplayed()) {
String text=(String) js.executeScript("return arguments[0].nextSibling.textContent.trim();", checkbox);
System.out.println(text);
}
}
}