java - Ignore case sensitivity while selecting option from a dropdown in Selenium Webdriver -


i have problem select dropdown menu using selectbyvisibletext ignoring case sensitivity. options' case dynamic.

example code have used :

public static void setdropdownvalue(by fieldid, string fieldvalue) {     select dropdown = new select(driver.findelement(fieldid));     dropdown.selectbyvisibletext(fieldvalue); } 

is there way can select option menu ignoring cases.

thanks

it not possible using selectbyvisibletext(text) if still want somehow. use this:

public static void setdropdownvalue(by fieldid, string fieldvalue) { select dropdown = new select(driver.findelement(fieldid)); int index = 0;     (webelement option : dropdown.getoptions()) {         if (option.gettext().equalsignorecase(fieldvalue))             break;         index++;     }     dropdown.selectbyindex(index); } 

one last point add, depending on structure of web page option.gettext() may not return option value need.

in such cases find attribute contains value of options in drop down , use option.getattribute("the attribute name containing value"). typically select attribute 'value', must use option.getattribute("value")

i hope helps :)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -