z5e56
V2EX  ›  问与答

XPATH 根据子元素定位问题

  •  
  •   z5e56 · Aug 2, 2023 · 579 views
    This topic created in 1022 days ago, the information mentioned may be changed or developed.

    https://github.com/NVlabs/stylegan2 此页面为例,页面中包含 3 个表格,尝试通过查找包含文本 Additional material 的 th 元素来定位第一个 table (不通过序数直接定位)

    下面为在 Chrome 控制台中的查找测试

    > $x('//table//th[text()="Additional material"]')[0].innerText // 能正确定位到该 th
    'Additional material'
    > $x('//table[//th[text()="Additional material"]]') // 返回了页面中的全部 3 个 table
    (3) [table, table, table]
    > $x('//table[descendant::th[text()="Additional material"]]') // 这个才返回了正确的 table
    [table]
    

    如上所示,请问一下

    1. 为什么第二个返回了所有 table ?
    2. //descendant:: 的区别是什么以及各自正确使用的场景应该是什么?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3630 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 62ms · UTC 10:24 · PVG 18:24 · LAX 03:24 · JFK 06:24
    ♥ Do have faith in what you're doing.