python - 使用 Python 和 selenium webdriver 单击没有 id/name 的按钮元素
问题描述
我正在使用 Python 和 selenium 扫描网页,我想单击一个如下所示的按钮:
稍后>
定义为:
<div class=”later___16eg8 col-xs-3of12”>
<button class=”visible-xs-inline visible-sm-inline visible-md-inline bdp___2gfNX textButton___ETrkF” data-test=”later-small-button”> == $0
“Later”
<span aria-hidden=”true”>></span>
</button>
<button class=”visible-lg-inline visible-xl-inline bdp___2gfNX textButton___ETrkF” data-test=”later-large-button”>
“Later”
<span aria-hidden=”true”>></span>
</button>
</div>
我试过了:
later = driver.find_element_by_xpath('//button[text()="Later"]')
later.click()
当第一行找到按钮(或其一部分)时,第二行会生成以下错误:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
我也试过:
later = driver.find_element_by_xpath('//button[text()="Later>"]')
这产生了以下错误:
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//button[text()="Later>"]"}
有任何想法吗?
谢谢
解决方案
你试过 //div[@class='later___16eg8 col-xs-3of12']/button/button[text()='Later']
推荐阅读
- .htaccess - 如何使用 htaccess 将变量添加到现有 url
- python - PyQt5在循环期间停止响应
- node.js - Node JS Streams:理解数据连接
- eclipse - 从 TestNG 的类路径中排除依赖项
- delphi - 在内联汇编器中调用 Exception.CreateRes
- javascript - javascript 在特定点 id 处将对象插入数组并增加其他 id
- excel - 查找包含特定年份的第一个日期
- python - 多个 TCP 到串行连接 python 尝试。
- kentico - Kentico 11 页面类型字段显示名称
- arrays - 如何使用 Sprintf 转义 YAML 文件获取的字符串中的单引号