【问题标题】:How to click an image given an Xpath in Selinum with Python?如何使用 Python 在 Selenium 中单击给定 Xpath 的图像?
【发布时间】:2020-04-18 05:26:53
【问题描述】:

所以我有 HTML 代码: enter image description here

如何点击此按钮?这个的 Xpath 是什么?

【问题讨论】:

标签: python selenium xpath


【解决方案1】:

该特定图像的 xPath 是

/html/body/img

点击它

 driver.findElement(By.xpath("/html/body/img")).click()

【讨论】:

  • 这不是正确的 XPATH。 OP 指的是图片中的按钮
【解决方案2】:

对于 xpath,您需要从顶层到此按钮的路径。 看起来像html\body\div\button [只是一个例子]。

您必须检查整个页面才能使用 xpath 导航到该按钮。

另一种更好的方法是使用 class="auth-button positive" 的 find 元素,然后使用 click() it

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2019-09-18
    • 2020-04-12
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    相关资源
    最近更新 更多