无法从特定的下拉菜单中选择项目(文本)?

时间:2019-07-18 15:56:30

标签: javascript java html selenium selenium-webdriver

当前,我正在尝试与一个下拉菜单进行交互,该菜单仅在单击后才显示特定文本。

看看下面的示例图片: enter image description here

<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代码中可以看到select的构造不同。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

一个选择是:

yourOption = element(by.id('react-select-2-input')).
yourOption.Click();
yourOption.sendKeys(Keys.DOWN);
yourOption.sendKeys(Keys.RETURN);

HTML的某处也必须有一个列表,该列表中将具有可供选择的选项。它可能不是输入的直接父项或子项。

相关问题