如何在Selenium中找到makemytrip.com“来自城市”输入字段?

时间:2019-07-24 05:27:32

标签: selenium

以下是该字段的html详细信息:

<input type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-owns="react-autowhatever-1" aria-expanded="true" class="react-autosuggest__input react-autosuggest__input--open" placeholder="From" value="">

下面在同一字段中尝试过但不起作用:

//div[@class='fsw_inputBox searchCity inactiveWidget activeWidget']/div/div/div/div/input

2 个答案:

答案 0 :(得分:0)

您在这里:

//input[@id='fromCity']

只是一个建议,请尽量避免在xpath中使用索引。使用索引时,如果在DOM中添加了一个元素(可能是由于设计更改或某些新功能的增加),则xpath可能不再保持有效,并会导致脚本失败。

答案 1 :(得分:0)

请尝试使用CSS选择器

input[placeholder="From"]

选择器上方只会给您一个结果。