首页 > 解决方案 > 蟒蛇,硒。如何按样式或 xpath 编号查找元素?

问题描述

<html>
 <body>
  <pre style="example" xpath="1">
   "amount": 12{
   "value" : 3
    },
  </pre>
 </body>
</html>

这是给定的。我将如何定位价值?

我在想这样的事情:

driver.find_element_by_xpath("//style='example'")

先感谢您!

标签: pythonseleniumxpathstyles

解决方案


在这种情况下,您需要使用整个 xpath:

driver.find_element_by_xpath("/html[1]/body[1]/pre[1]")

推荐阅读