How loop drop down value using Selenium JAVA -


i have dropdown countries follows,

enter image description here

i want send values us,ca,af,al,dz,as,ad array, loop , print using selenium , java.

i tried following

webelement elementdrop = d.findelement(by.xpath("path")); list<webelement> dropdownvalues = d.findelements(by.xpath("path")); for(webelement value:dropdownvalues) {    string pcvalues=value.gettext();   system.out.println("value names" + pcvalues);  } 

this print united states canada afghanistan albania etc. want ca af al dz ad

 webelement dropdown = driver.findelement(by.name("country"));   list<webelement> options = dropdown.findelements(by.tagname("option"));   iterator<webelement> it=options.iterator();     while(it.hasnext())     {       system.out.println(it.next().getattribute("value"));     } 

give try , let me know if works.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -