【发布时间】:2019-04-10 05:43:11
【问题描述】:
我正在尝试为以下 html 标记查找 xpath。但无法在 selenium 中找到。因为我是初学者,所以我需要一些帮助和建议。出现错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class='react-autosuggest__input react-autosuggest__input--open']"}
(Session info: chrome=73.0.3683.103)
这是 HTML 元素。
<input type="text" autocomplete="off" aria-autocomplete="list" aria-controls="react-autowhatever-1" class="react-autosuggest__input react-autosuggest__input--open" placeholder="From" value="">
我已经尝试为上面的 HTML 制作了这个 xpath。但是同样会抛出错误。
//*[@class='react-autosuggest__input react-autosuggest__input--open']
我希望上述 xpath 的输出能够定位 selenium 中的元素,但实际上我遇到了错误。
【问题讨论】:
-
//input[@class='react-autosuggest__input react-autosuggest__input--open'] 你试过这种方式吗? ?请确认是否存在具有相同类名的其他输入类型。
-
嗨@Dhru'soni。我刚刚试过这个。但得到一些错误。 “消息:无效选择器:无法使用 xpath 表达式定位元素 //input[@class='react-autosuggest__input react-autosuggest__input--open'] '] 因为以下错误:SyntaxError: 无法执行'评估'关于 'Document':字符串 '//input[@class='react-autosuggest__input react-autosuggest__input--open'] ']' 不是有效的 XPath 表达式。”
标签: python selenium xpath css-selectors webdriverwait