【发布时间】:2019-11-27 14:58:32
【问题描述】:
目前我正在尝试与一个下拉菜单进行交互,该下拉菜单仅在单击后显示特定文本。
<div class="" style="display: inline-block;">
<input autocapitalize="none" autocomplete="off" autocorrect="off" id="react-select-2-input" spellcheck="false" tabindex="0" type="text" aria-autocomplete="list" value="" style="box-sizing: content-box; width: 4px; background: 0px center; border: 0px; font-size: inherit; opacity: 1; outline: 0px; padding: 0px; color: inherit;"><div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 12px; font-family: sans-serif; font-weight: 300; font-style: normal; letter-spacing: normal; text-transform: none;">
</div>
</div>
正如您从上图中看到的那样,在单击元素时文本是可见的,但是当我检查元素时,我看不到任何下拉文本项?
我尝试了以下方法:
- 点击元素 > 然后使用链接文本
- 使用列表循环遍历元素
- 点击元素,然后尝试发送密钥
- 另外,我无法使用 select,您可以从 html 代码中看到它的构造方式不同。
有什么想法吗?
【问题讨论】:
-
您是否尝试使用仅包含特定文本的定位器 - 例如 - "//*[contains(text(),'Newcastle')]"
-
不幸的是@Sureshmani 文本不可见
-
您能否将光标移到上方并右键单击并检查这些列表值?
-
你试过按值选择吗? public static void dropDownSelectByValue(WebElement webElement, String Value){ Select selObj=new Select(webElement); selObj.selectByValue(Value);如果您的 HTML 中没有列表,我怎么确定我的解决方案可能没有帮助
-
感谢您的帮助@Devdun,找到了答案附在线程上:)
标签: javascript java html selenium selenium-webdriver