selenium webdriver - How to select element from options populated -


i need write script selenium-webdriver. stuck in situation need enter text (e.g : "tt") in textbox , list gets populated (hidden values). need select option populated list. (like in "google" search).

<div class="select2-search">   <input type="text" autocomplete="off" class="select2-input tabindex="-1" style> </div> <ul class="select2-results"> <li class="select2-results-dept-0 select2-result select2-result-selectable select2-new">   <div class="select2-result-label">     <span class="select2-match">et</span>   </div> </li> <li class="select2-results-dept-0 select2-result select2-result-selectable select2-highlighted">   <div class="select2-result-label">"secr"     <span class="select2-match">et</span>"ary"   </div> </li> <ul> 

so i'll write little code you.

i'm using www.google.com exemple.

webelement inputelement = driver.findelement(by.id("gbqfq")); // input inputelement.sendkeys("zyzz"); // want search him on internet ;) // suggestions in list list<webelement> suggestionlist = driver.findelements(by.cssselector(".gsq_a table tbody tr td:first-of-type span")); 

to select option have 2 choices, first :

// random option , click on suggestionlist.get(1).click(); 

or

// want click on link contains that. for(webelement elem: suggestionlist) {   string text = elem.gettext();   if(text.equals("zyzz motivation"))   elem.click(); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -