【问题标题】:Find element contains specific "path" attribute查找元素包含特定的“路径”属性
【发布时间】:2021-11-13 21:33:19
【问题描述】:

有人可以帮忙解决以下问题吗?

我的地图加载了 2000 多个元素,但其中只有一个(当前可见)的元素“path”的属性 d 不同于零。为便于理解,请参考以下截图:

试过这个:SVG & Path finding,但没有找到我要找的东西。

并且拥有这个 XPath:

//div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and @d="M0 0"]

找到所有这些 (2000)。

我正在寻找的是这样的(虽然我找不到正确的解决方案) - 故意只是添加了 Xpath 的结尾。

总之,我需要 d 属性(路径内)不包含零值:

//*[name()='svg']//*[name()='path' and @d(contains,"125")]

请协助,并在此先感谢您。

【问题讨论】:

    标签: javascript xpath css-selectors cypress


    【解决方案1】:

    根据您的描述,您正在寻找 d 属性值为 not 等于 M0 0 的定位器。
    这可以使用 not 运算符转换为 XPath。
    请试试这个:

    //div[@id="map"]//div[contains(@class,"map")]//div[@class="leaflet-pane"]//div[@class="leaflet-pane2"]//*[name()='svg']//*[name()='path' and(not(@d="M0 0"))]
    

    【讨论】:

      猜你喜欢
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2011-12-16
      • 2015-12-19
      相关资源
      最近更新 更多