How to find dynamically created elements in drop-down list based on input Selenium?



  • 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">



  • 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();


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2