2

I have a web-element which on click produces a dropdown, I am able to click on web-element and see see all the elements using the code.

By mySelector = By.xpath("//li[contains(@class,'ant-select-dropdown-menu-item')]");
List<WebElement> myElements = driver.findElements(mySelector);
        for (WebElement e : myElements) {
            System.out.println(e.getAttribute("outerHTML"));
        }

Also

driver.findElement(By.xpath("//li[text() = '"
                    + user.getHomeLocation() + "']")).isDisplayed();

returns true

But I am not able to click the desired value.I want to click Westminster

<li unselectable="unselectable" class="ant-select-dropdown-menu-item-active ant-select-dropdown-menu-item" role="menuitem" aria-selected="false" style="-moz-user-select: none;">Select</li>
<li unselectable="unselectable" class="ant-select-dropdown-menu-item" role="menuitem" aria-selected="false" style="-moz-user-select: none;">Basking Ridge</li>
<li unselectable="unselectable" class="ant-select-dropdown-menu-item" role="menuitem" aria-selected="false" style="-moz-user-select: none;">Highlands Ranch</li>
<li unselectable="unselectable" class="ant-select-dropdown-menu-item" role="menuitem" aria-selected="false" style="-moz-user-select: none;">Westminster</li>
Prashant Raghav
  • 319
  • 2
  • 6
  • 15
  • Your code trial `to click on web-element`? Additionally instead of the output by `outerHTML` update the question with the relevant HTML of the dropdown – undetected Selenium Sep 21 '18 at 08:44

1 Answers1

0

Try to add one more 'contains' to xpath locator with needed item:

//li[contains(@class,'ant-select-dropdown-menu-item')][contains(.,'Westminster')]