Reputation: 86915
Is it possible to open a Vaadin
ComboBox
by code?
I'd like to present 2 comboboxes that depend on each other. When the user selects a value in the first, I'd like the 2nd combobox to automatically open the possible selections, so that the user can directly select one, instead of having to open the 2nd combobox himself.
Maybe there is an event that I could send to trigger the opening?
Upvotes: 2
Views: 1917
Reputation: 2906
I've done this in Vaadin 7 with Selenium WebDriver:
public void selectValueInCombobox(WebElement cmb, String value) {
cmb.findElement(By.tagName("div")).click(); //shows the menu
List<WebElement> findElements = webDriver.findElements(By.cssSelector("td[role='listitem']"));
findElements.stream()
.filter(item-> value.equals(item.findElement(By.tagName("span")).getText()))
.findFirst().get().click();
}
The WebElement is the Combobox (its the div when rendered in html), and value is the listitem in the combobox you want selected.
Upvotes: 3
Reputation: 647
The only thing I can think of is, after giving focus to the combobox, try sending it a keystroke (ie the down arrow to try and make it open). There is a good example here
The other way, maybe to try and use Selenium to trigger the combobox, but thats probably overkill. For examples of that, look into vaadin's testbench.
Upvotes: 2