1

enter image description here

First time here. I've got an issue you might be able to help with. Working on chrome webdriver automation, there's a dropdown menu that's toggled with a click. I need to be able to select list items. Here is the code for the menu.

 <button type="button" class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" title="None selected" aria-expanded="true"><span class="multiselect-selected-text">None selected</span> <b class="caret"></b></button>

class="multiselect-container dropdown-menu"

My attempts to interact with it through the following have failed.

new Select(driver.findElementByXPath("//button[@type='button']")).selectByVisibleText("TEST");

If you need any more information please ask, not familiar with what might be required. Many thanks

UPDATE; Thanks for the replies. "Select by option name" doesn't seem to work. Using that code with my xpath i get the following

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "button"

"Select by option value" gives the same error.

I found the xpath and class via css using the chrome selenium IDE, however maybe it's incorrect as the below fails to toggle the dropbox and gives the following error. Also i'm in the correct iframe as i can interact with another element.

driver.findElementByXPath("//button[@type='button']").click();
driver.findElementByCssSelector(".multiselect.dropdown-toggle.btn.btn-default").click();

org.openqa.selenium.ElementNotVisibleException: element not visible

Might i be referencing the element in an incorrect way? Many thanks

update2: I feel like i might be getting close.

 driver.findElementById("ptp_sl").click();


 unknown error: Element <select class="userdropdown" id="ptp_sl" multiple="multiple">...</select> is not clickable at point 
4

1 Answer 1

2

The below code will locate the dropdown and prints the list of options present in the dropdown.Check whether the below mentioned first two line of code is locating your dropdown.And I have added next few lines to check whether all the dropdown options are displayed.

WebElement we = driver.findElement(By.xpath("//select[@class='userdropdown']"));
Select dropdown = new Select(we);
List<WebElement> alloptions = dropdown.getOptions();
for(WebElement option:alloptions)
{
dropdown.selectByVisibleText(option.getText());
System.out.println(option.getText());
}
2
  • Hi mate, thanks for your reply. Didn't work initially but made edits to findbyId and all the users were printed. Absolutely brilliant. All of the options print in the Console. What's the final piece of the puzzle to select them in the combobox? Thanks EDIT: They were being selected by didn't update the combobox text. Many thanks ! Jun 19, 2018 at 4:39
  • @Lewis just try by adding the code dropdown.selectByVisibleText("your text in the combobox"); below the Select dropdown code.Just comment out if it works.....
    – shanila
    Jun 19, 2018 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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