How do I select an item in the list of menu items once it appears as a dropdown? I tried sendKeys to input the text like "Brown Mustard", but it clears out when I hit the submit button. I know I should be able to type it in the field but WebDriver sendKeys didn't work, so if you have suggestions on how to select from a list menuitems, thanks so much!
Here's the html snippet of the text field and the menu items that appear when you enter say "B"
<input id="combobox0-text" class="ui-autocomplete-input ui-widget
ui-widget-content tableRightFormTextField" autocomplete="off"
role="textbox" aria-autocomplete="list" aria-haspopup="true">
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all"
tabindex="-1">Bro<strong>w</strong>n Mustard</a></li>
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all"
tabindex="-1">Bro<strong>w</strong>ntop</a></li>
you can try using wait,
new WebDriverWait(driver, 60).until(ExpectedConditions.visibilityOfElementLocated(By.id("combobox0-text"))).clear();
driver.findElement(By.id("combobox0-text")).sendKeys("Brown Mustard");
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.ui-menu-item"))).click();
the above code will clear the input field
and type in the required item
and wait for the menu item to appear in the drop down...,the 3rd statement will click on the menu item
..
This is how it shall work:
driver.FindElement(By.Id("combobox0-text")).Clear();
driver.FindElement(By.Id("combobox0-text")).SendKeys("bro");
driver.FindElement(By.CssSelector("li.ui-menu-item")).Click();
FYI: It shall select the first/top menu item after sending keys. So, type more keys if you wanted to select a particular item.
After entering B, you could create a select object of the menu items and then select items based on visible text
import org.openqa.selenium.support.ui.Select;
//your code before entering B
Select menu = new Select(driver.findElement(By.id("combobox0-text")));
menu.selectByVisibleText("Brown Mustard");