Skip to content Skip to sidebar Skip to footer

Xpath How To Get Text When The Brother Is Not An Element

i used to have this form;
  • name:

    Seca

  • and I was using this xpath to get the seca: ul/li/span[normalize-s

    Solution 1:

    Now, "Seca" is just another child of the li element - and thus a following sibling of the span element. Using

    //ul/li/span[normalize-space(text())='name:']/following-sibling::text()
    

    gives you

    [EMPTY LINE]
    Seca
    [EMPTY LINE]
    

    you might want to exclude those whitespace-only lines:

    normalize-space(//ul/li/span[normalize-space(text())='name:']/following-sibling::text())
    

    and the result will be

    Seca
    

    If your actual input includes more text nodes, do not forget to add [1]to the expression.


    Note that the expression could be a lot easier if there is actually no reason to normalize the text content of span and to only consider its immediate child text nodes:

    //ul/li[span='name:']/text()[2]

    Post a Comment for "Xpath How To Get Text When The Brother Is Not An Element"