Hey,
1) In the first case I assume that you know the
option that you want to pick from the 2nd drop down control once AJAX call is complete.
So, the idea of this approach is to keep trying selecting that specific
option from the 2nd drop down for a certain amount of time (hoping that withing that time the 2nd dropdown gets the updated list of options and you'll be able to pick your
option).
Hope it's not too confusing, but let's have a look at the code that I assume should work :) :
SelectElement select = new SelectElement(driver.FindElement(By.XPath("//path_to_drop_down"))); //here we locate the 2nd dropdown
WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); //creating a wait object assining 10 seconds wait time
//And now try picking the option from the dropdown by value (e.g. "Value1"). The code will keep for 10 second.
w.Until(ctx =>
{
try
{
select.SelectByValue("Value1"); //attempt to pick option by value. If failed => NoSuchElementExeption is thrown (go to catch block then)
return true; //yay, SelectByValue didn't throw an exception. Means it managed to pick the option we were after. Returning 'true' to stop.
}
catch (NoSuchElementException) //tried to pick option but it wasn't there. Handling exception to prevent it from stopping our test execution.
{
return false; //no good, this iteration was not a success. So telling the "Until" method to try again if we still have time left (<10 sec)
}
});
2) The second situation is when you just want to know if the ajax call that populates 2nd dropdown has finished. That is tricky (async calls are always triky to track) but you may want to look in direction of JavaScript/JQuery methods calls from you test code (more info:
https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done).