python - 如何通过 xpath 获取此 html 代码以在 python 上使用 selenium?
问题描述
我有一个更新按钮,在 python 中,机器人我想点击这个按钮,但我尝试了很多选项但不起作用我无法通过 XPath 定位元素。请帮我?谢谢你的帮助。
注意:我需要使用文本“更新”来定位,因为网页上有很多按钮。
<span class="a-spacing-top-small">
<span class="a-button a-button-primary a-button-small sc-update-link" id="a-autoid-2">
<span class="a-button-inner">
<a href="javascript:void(0);" data-action="update" class="a-button-text" role="button" id="a-autoid-2-announce" style="">Update
<span class="aok-offscreen">Nike Academy 18 Rain Jacket Men's (Obsidian, M)</span>
</a>
</span>
</span>
</span>
解决方案
这应该有效:
button = driver.find_element_by_xpath("//a[@data-action,'update']")
其中驱动程序是您的驱动程序实例。
推荐阅读
- java - 连接到Android设备时如何获取WIFI提供商名称
- vaticle-typedb - 无法在 Grakn 中创建 [id] 属性
- cpu-architecture - 内存屏障会阻止分支预测吗?
- json - 尝试通过 jsondecoder 解码 json 时出错
- php - Laravel - 将自定义参数发送到计划任务(命令)
- string - 在 PostrgreSQL 中恢复对字符串的添加
- connectiq - 将带有组的锻炼添加到会话中
- visual-studio - 为什么我在 Visual Studio 中找不到 ResourceDictionary 模板?
- asp.net-core - int/string 的类型似乎导致错误
- java - 如何使用 JAVA/Groovy 从 Jmeter HTTP 采样器中删除空的 HTTP 请求参数