How to list all the checkboxes available in a webpage by displaying their Visible Text in selenium using Java?
-
1It's very easy. Just find elements by tag name.Buaban– Buaban2016-07-15 09:54:12 +00:00Commented Jul 15, 2016 at 9:54
-
Could you share HTML as well???Saurabh Gaur– Saurabh Gaur2016-07-15 10:12:00 +00:00Commented Jul 15, 2016 at 10:12
-
This is the Webpage mygrocerychecklist.com @SaurabhGaurSurendra Anand– Surendra Anand2016-07-15 11:30:15 +00:00Commented Jul 15, 2016 at 11:30
Add a comment
|
1 Answer
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);
}
}
}