[Python] XPATH for the descendant of an ancestor above of the current node

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    <oc-resume-upload>
    <div data-test="resume-upload-container" class="form-section">
    <div class="flex flex-column">
    <h2 class="form-section-header form-section-header--required"> **Resume **</h2>
    <div>
    <div>
    <div ocappdrag="" class="dropzone dropzone-upload">
    <oc-file-upload-button _nghost-ng-c1329912542="">
    <div _ngcontent-ng-c1329912542="">
    **<button _ngcontent**-ng-c1329912542="" type="button" data-test="resume-upload" aria-label="Upload resume" class="padding--m button button--clean">
    <span class="font-size--s font--bold">
    <strong>Select file</strong>, or drop file here
    </span>
    </button>


    So basically my current node is the button _ ngcontent and I want to find the first Content (in type text) available in his ancestor or children of ancestors. In this case I would like to have the text of the h2 tag that has "Resume" as content.

    './ancestor::*[normalize-space(.//*)][1]'


    This code allows to find text in any descendants of ancestors or ancestors but problem is, it also find my descendants. As such I get "Select File" from the tag which i dont want.

    ./ancestor::*[normalize-space(string(.)) and not(self::*) and not(.//*)][1]


    Should be the one working since I exclude my node and my node descendants but in this case I dont find anything ...

    Continue reading...

Compartilhe esta Página