【发布时间】:2019-02-25 14:56:48
【问题描述】:
我有一个 web 元素,点击后会生成一个下拉列表,我可以点击 web 元素并查看使用代码的所有元素。
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"));
}
还有
driver.findElement(By.xpath("//li[text() = '"
+ user.getHomeLocation() + "']")).isDisplayed();
返回真
但我无法点击所需的值。我想点击威斯敏斯特
<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>
【问题讨论】:
-
您的代码试用版
to click on web-element?此外,不是outerHTML的输出,而是使用下拉列表的相关 HTML 更新问题
标签: selenium automation automated-tests