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">&nbsp;     british <input type="checkbox" name="british" value="british">&nbsp;     north <input type="checkbox" name="north" value="north">&nbsp;     southeast <input type="checkbox" name="southeast" value="southeast">&nbsp;     west <input type="checkbox" name="west" value="west">&nbsp;     spanish <input type="checkbox" name="spanish" value="spanish">&nbsp;     europian <input type="checkbox" name="europian" value="europian">&nbsp;     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

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -