java - How to store the matched condition in a variable which can be clicked using selenium -


i have value in excel , checking existence in array of elements in drop down. condition passes, want store , click. tried store in string but, not clickable. tried store in web element failed. kindly help.

list<webelement> countrylist = driver.findelements(by.cssselector("ul.ui-multiselect-checkboxes li label[for*='ddlbu'] span")); list<string> all_countrylist = new arraylist<>(); thread.sleep(1000); string selectedcountry = driver.findelement(by.xpath("html/body/div[9]/ul/li[2]/label/span")).gettext(); webelement clickselectedcountry = driver.findelement(by.xpath("html/body/div[9]/ul/li[2]/label/span")); thread.sleep(1000); for(int cui = 0; cui < countrylist.size(); cui++) {     all_countrylist.add(countrylist.get(cui).gettext());     if((countrylist.get(cui).gettext()).equalsignorecase(countrysheet.getcell(0, 2).getcontents()))     {         system.out.println("the country " + (countrysheet.getcell(0, 2).getcontents()) + " existing");          string clickcountry = (countrylist.get(cui).gettext());     }     else     {         system.out.println("\nselected country " + (countrysheet.getcell(0, 2).getcontents()) + " not existing");      } } 

try below code.

 string countrytobeselected = countrysheet.getcell(0, 2).getcontents();   selectedcountrylocator = by.xpath("html/body/div[9]/ul/li[2]/label/span");   string selectedcountry=driver.findelement(selectedcountrylocator).gettext();   //if country other selected country, click , open list   if(!countrytobeselected.equals(selectedcountry)){         webelement clickselectedcountry=driver.findelement(selectedcountrylocator);         clickselectedcountry.click();          //get list of countries in webelement list         list<webelement> countrylist = driver.findelements(by.cssselector("ul.ui-multiselect-checkboxes li label[for*='ddlbu'] span"));          //store country details in list         list<string> all_countrylist=new arraylist<string>();          //iterate on webelement list , store country values in string list         for(webelement country : countrylist){             all_countrylist.add(country.gettext());         }          //get expected country index         int elementindex = all_countrylist.indexof(countrytobeselected);          //click on after finding country index         countrylist.get(elementindex).click();   } 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -