【问题标题】:Why can't the element be found with the correct xpath using Inspector tool Chrome?为什么无法使用 Inspector 工具 Chrome 找到正确的 xpath 元素?
【发布时间】:2025-12-13 04:10:01
【问题描述】:

试图获取动态加载元素的 xpath。该元素表示图表中的一个点。它包含一个我想提取的属性值。我使用 Chrome 中的 Inspector 工具来获取元素的 xpath。我可以复制 xpath,但是当我尝试在 chrome 检查器工具中粘贴复制的 xpath 时,找不到任何元素。我可以使用这种方法在页面上找到其他元素。

为什么会这样?我在 html 中找不到任何 iframe,也找不到任何隐藏元素。我的目的是找到该元素的 xpath 以将其与 Selenium 一起使用。

【问题讨论】:

    标签: selenium google-chrome web-inspector


    【解决方案1】:

    开发工具不适用于svg, g, path, circle, canvas 之类的标签。所以你不能自动生成它们。

    您可以为提到的tags 自己写xpath,类似这样:-

    //*[name()='svg']
    

    定位svg 标签

    假设您想为突出显示的项目(屏幕截图)写xpath,您可以这样做:-

    //*[name()='g' and contains(@class, 'recharts-layer recharts-line-dot')]//*
    

    【讨论】:

      最近更新 更多