selenium - How to get text (label) of all checkboxes -
i've been trying label value inside checkboxes in page, far have been using code automate html below.
java:
list<webelement> allcbox = driver.findelements(by.xpath("//input[@type='checkbox']")); for(webelement checkbox : allcbox ) { system.out.println("--- "+checkbox.gettext()); } html:
<html> <p> regions: south <input type="checkbox" name="south" value="south"> british <input type="checkbox" name="british" value="british"> north <input type="checkbox" name="north" value="north"> southeast <input type="checkbox" name="southeast" value="southeast"> west <input type="checkbox" name="west" value="west"> spanish <input type="checkbox" name="spanish" value="spanish"> europian <input type="checkbox" name="europian" value="europian"> northeast <input type="checkbox" name="northeast" value="northeast"> </p> </html>
in case <input> doesn't have text attribute, labels equal "name" , "value" attribute. can "name" or "value" attribute.
list<webelement> checkboxlist = driver.findelements(by.xpath("//input[@type='checkbox']")); for(webelement checkbox : checkboxlist) { system.out.println(checkbox.getattribute("name")); }
Comments
Post a Comment