【发布时间】:2021-09-01 05:37:59
【问题描述】:
这是一个搜索页面。它的结构是这样的。
<input type="search" title="Search Site" aria-label="Keywords" placeholder="Keywords" autocomplete="off" value="">
<div class="header2020-search-button">
<button class="fast fat-search">
<span class="hid-text">Search</span>
</button>
</div>
我正在尝试使用 selenium 与此文本框交互并搜索单词 Collapse。我的代码是这样的
driver.find_element_by_xpath("//input[@title='Search Site')]").send_keys("Collapse")
driver.find_element_by_xpath('//button[@class="fast fat-search"]').click()
发送键不起作用。导致错误。
selenium.common.exceptions.InvalidSelectorException:消息:无效 选择器:无法使用 xpath 表达式定位元素 //input[@title='Search Site')] 因为以下错误: SyntaxError:无法对“文档”执行“评估”:字符串 '//input[@title='Search Site')]' 不是有效的 XPath 表达式。
非常感谢。
【问题讨论】:
标签: python selenium xpath find element