i have a search box, when i do search a value, say a bank name, it displays the results matching the text given on the search box. But the catch here is it may not an exact result, and also it takes some seconds to load in a complete list, by refreshing intellectually within the search results. so even if i wait for some results to load, it gets the values immediately whatever came at that moment, but actually it refreshes the list even after couple more seconds. So how can i wait for complete load and then take out the results. any help on this please.
code snippet
<ul class="DropDown__options DropDown__options--small--focused DropDown__options--focused" id="searchTopBank-listbox" role="listbox" aria-activedescendant="searchTopBank-options-4">
<li aria-selected="true" class="DropDown__option TypeAhead__option DropDown__option--focused DropDown__option--small" id="searchTopBank-options-0" role="option">
<img alt="" class="dropdown-logo" src="data">
<span>
<span class="DropDown__matched-option-chars">Bank of America</span>
</span>
</li>
<li aria-selected="false" class="DropDown__option TypeAhead__option DropDown__option--focused DropDown__option--small" id="searchTopBank-options-1" role="option">
<img alt="" class="dropdown-logo" src="data">
<span>First National
<span class="DropDown__matched-option-chars">Bank of America</span>
</span>
</li>
<li aria-selected="false" class="DropDown__option TypeAhead__option DropDown__option--focused DropDown__option--small" id="searchTopBank-options-2" role="option">
<img alt="" class="dropdown-logo" src="data:image/png;base64, null">
<span>Second National Farmer's
<span class="DropDown__matched-option-chars">Bank of America</span>
</span>
</li>
<li aria-selected="false" class="DropDown__option TypeAhead__option DropDown__option--focused DropDown__option--small" id="searchTopBank-options-3" role="option">
<img alt="" class="dropdown-logo" src="data:image/png;base64, null">
<span>
<span class="DropDown__matched-option-chars">Altabank</span>
</span>
</li>
<li aria-selected="false" class="DropDown__option TypeAhead__option DropDown__option--focused DropDown__option--hover DropDown__option--small" id="searchTopBank-options-4" role="option">
<img alt="" class="dropdown-logo" src="data:image/png;base64, null">
<span>Freedom
<span class="DropDown__matched-option-chars">Bank of America</span>
</span>
</li>
</ul>
I would suggest doing something like this:
WebDriverWait wait = new WebDriverWait(driver, 20);
public void wait(int delay){
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
String searchResult = "//li[contains(@id,'searchTopBank-options')]";
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(searchResult)));
int initialAmount = driver.findElements(By.xpath(searchResult)).size();
while(true){
wait(200);
int newAmount = driver.findElements(By.xpath(searchResult)).size();
if(newAmount > initialAmount){
initialAmount = newAmount;
}else{
break;
}
}
The wait amount depends on the slowest actual speed of bringing the new search results.