2

I'm trying to test a page that has an input but really its a drop down list. The user enters text and then a dropdown appears based on what the user inputted. They are groups that are in the database. If I look for these elements before typing anything they dont exist but once I start typing they do exist. The problem is I cant just type the whole name and then press enter or return because an option has to be selected from the list. I can press arrow down to get the focus on the item from the list but then if I say enter it doesnt select, it sends that enter to the original element and nothing gets selected. I can find the select element:

var ddList = driver.FindElement(By.CssSelector(".ui-autocomplete-input"));
ddList.SendKeys("Admins");

This is the first time the list appears in the html. It looks like this:

<li class="ui-menu-item" role="presentation">
  • <li class="ui-menu-item" role="presentation"> Can't see this without editing the comment for some reason – Darian Everett Apr 2 '14 at 21:07
  • Did you tried with Ajax control to click on the element ? – user18477 May 24 '16 at 16:45
2

Why don't you just type into the element like you said, and then find the elements? You can just make an array of them, but I assume from what you said that if you type the whole name then just one will appear, so that should be easy enough.

//your code

Thread.Sleep(500); //may have to adjust this based on how long it takes to generate; you can also sleep the driver itself if you want

var elements = driver.FindElements(By.CssSelector(".ui-menu-item")).ToArray();
var visible = elements.Where(r => r.Displayed).ToArray();
visible[0].Click();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.