Here is code that I am using firstly I am clicking on the button then the list of items is shown and I try to select from the list but it said that Index=0, Size=0 when I use Xpath. When I use the class_name it said "Element not Visible". Here is code for this:

java.util.List<WebElement> listItems1 = driver.findElements(By.className("dropdown-menu"));

Here is the code in the the inspect element:

<div class="dropdown open">
    <button class="btn-blue-simple btn dropdown-toggle" type="button" id="add_new_item_btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
      <span class="caret"></span>
    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">

          <a class="pull-left" onclick="showPopup(&quot;Add Labor Item&quot;, '/quote_items/new?item_type=labor&amp;product_category_id=1912275102536303582&amp;quote_id=1949426380886245765')" href="javascript:void(0)">Labor</a>
          <a class="pull-left" onclick="showPopup(&quot;Add Parts Item&quot;, '/quote_items/new?item_type=part&amp;product_category_id=1912275102796350432&amp;quote_id=1949426380886245765')" href="javascript:void(0)">Parts</a>
          <a class="pull-left" onclick="showPopup(&quot;Add Warranties Item&quot;, '/quote_items/new?item_type=warranty&amp;product_category_id=1912275103022842850&amp;quote_id=1949426380886245765')" href="javascript:void(0)">Warranties</a>
  • 1
    What happens when you change driver.findElements(By.className("dropdown-menu")); to use the "pull-left" class? Commented Jan 4, 2019 at 18:32

1 Answer 1


It seems you're looking at the upper hierarchy in the DOM. Try the below code; the intent is to click on the first index.

// some explicit wait goes here
List<WebElement> dropdown_items = new ArrayList<>();
dropdown_items = driver.findElements(By.xpath("//div[@class='dropdown open']//li//a"));

After this proof works, you might need to refactor this to a method to imitate the behavior of an actual Select class over your dropdown.

Your Answer

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

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