0

How to list all the checkboxes available in a webpage by displaying their Visible Text in selenium using Java?

3
  • 1
    It's very easy. Just find elements by tag name. Commented Jul 15, 2016 at 9:54
  • Could you share HTML as well??? Commented Jul 15, 2016 at 10:12
  • This is the Webpage mygrocerychecklist.com @SaurabhGaur Commented Jul 15, 2016 at 11:30

1 Answer 1

1

For that website this should do

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);
            }
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.