Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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">
share|improve this question
    
<li class="ui-menu-item" role="presentation"> Can't see this without editing the comment for some reason –  Darian Everett Apr 2 at 21:07

1 Answer 1

up vote 1 down vote accepted

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();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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