首页 > 解决方案 > Python Selenium 找不到 XPath

问题描述

我需要找到文本的 XPath(你能找到我吗?): 在此处输入图像描述

尝试了大约 10 分钟,但无法做到。

标签: pythonseleniumweb-scrapingxpath

解决方案


你有身份证,用它。

driver.find_element_by_id("modal-root-header").text

如果 id 由于某种原因不是唯一的,请使用 xpath:

driver.find_element_by_xpath("//h4[@id='modal-root-header']").text

如果.text不起作用,请尝试.get_attribute("value"),或.get_attribute("innerText")


推荐阅读