Eleshar
Eleshar

Reputation: 513

PAD JQuery - inner text in sibling of a parent

I am using Power Automate Desktop to get information from a dynamically generated website. The elements go very deep and they don't mostly have usable handles, so I need to use the inner text to navigate around the document.

I am able to get to the static text element with label:contains("static text"), the hidden one with label:contains("static text") + div but I can't seem to be able to get to the one I get.

I tried label:contains("static text"):parent() + div but this returns the hidden static text as well for some reason. Interestingly, getting text from label:contains("static text"):parent():parent() returns the visible static text and label:contains("static text"):parent():parent():nth-child(2) cannot be found...

<div>
  <div>
    <div>
      <ul>
        <li>
          <div>
            <label>
              STATIC TEXT I CAN FIND
            </label>
            <div>
              HIDDEN STATIC TEXT I DON'T CARE ABOUT
            </div>
          </div>
          <div>
            <div 3x>
              <li>
                <div 3x>
                  <ul></ul>
                  <div>
                    DYNAMIC TEXT I WANT TO EXTRACT
                  </div>
                </div>
              </li>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</div>

Upvotes: 1

Views: 953

Answers (2)

Severiano Cuellar
Severiano Cuellar

Reputation: 84

I copy pasted your code into this online html editor: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro just after the "My first paragraph" code.

Using ~ siblings , has and contains selector in PAD (selector builder in text mode) I was successful to get the text you want in a variable: "DYNAMIC TEXT I WANT TO EXTRACT" :

iframe[Id="iframeResult"] > html > body > div > div > div > ul > li:has(label:contains('STATIC TEXT I CAN FIND')) ~ li > div > div

enter image description here

Upvotes: 0

You could do something like:

$("label:contains('STATIC TEXT I CAN FIND')").closest('div').parent().next().find('ul').next().html()

or

$("div > div > div > ul > li:eq(1) > div > div").html();

Upvotes: 0

Related Questions