如何在selenium中列出复选框?

时间:2016-07-15 09:25:31

标签: java selenium selenium-webdriver

如何通过使用Java在selenium中显示其可见文本来列出网页中可用的所有复选框?

1 个答案:

答案 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);
            }
        }
    }