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>

1
  • 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 Commented Sep 21, 2018 at 8:44

1 Answer 1

0

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

//li[contains(@class,'ant-select-dropdown-menu-item')][contains(.,'Westminster')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.