尝试在搜索字段

时间:2018-01-29 07:25:58

标签: selenium xpath

我无法将密钥发送到可搜索的下拉列表。我可以使用:

扩展下拉列表
(//*/label[contains(text(),'Country of company registration')]/following-sibling::div//span[3]/span).click();

但是当我尝试将一些密钥发送到搜索字段时,我得到:

org.openqa.selenium.ElementNotInteractableException: Element <div class="Select-input"> is not reachable by keyboard

我用于搜索字段的Xpath“Select-input”是:

//*/label[contains(text(),'Country of company registration')]/following-sibling::div//span/div[2]

我还尝试将文本发送到“选择值”,但我收到了类似的错误。 “选择值”的Xpath是:

//*/label[contains(text(),'Country of company registration')]/following-sibling::div//span/div[1]

完整对象:

<div class="form-group">
<label class=" form-control-label" for="countryCode">Country of company registration</label>
<div class="Select Select--single is-clearable is-searchable has-value">
<div class="Select-control">
<span id="react-select-12--value" class="Select-multi-value-wrapper">
<div class="Select-value">
<span id="react-select-12--value-item" class="Select-value-label" role="option" aria-selected="true">United Kingdom</span>
</div>
<div class="Select-input" style="display: inline-block;">
<style>input#undefined::-ms-clear {display: none;}</style>
<input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-12--value" value="" style="width: 19px; box-sizing: content-box;"/>
<div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 16px; font-family: "Larsseit",sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"/>
</div>
</span>
<span class="Select-clear-zone" title="Clear value" aria-label="Clear value">
<span class="Select-clear">×</span>
</span>
<span class="Select-arrow-zone">
<span class="Select-arrow"/>
</span>
</div>
</div>
</div>

*为格式化道歉。

编辑:我不相信我的问题与建议的问题重复。我已经进行了冗长的等待以及明确的等待以确保下拉已经扩展。我认为问题可能是由于下拉列表的动态特性,因此无法获得准确的xpath。这只是猜测。感谢。

1 个答案:

答案 0 :(得分:1)

我认为问题可能在于您不是在输入元素中尝试输入,而是在div元素中。

你可以尝试一下:

//input[@role='combobox']

让我知道它是否适合你。