1

I have the following HTML I need to scrape, but the only reliable handle is a stable description of a text field. From there, I need to go to its parent, find that parents next sibling and then get the descendents (unfortunately the data-automation-id selector repeats in every such iteration of this snippet on the site). I put together the below XPath but my RPA tool is unable to find it in the document.

XPath

div[contains(text(),'STABLE TEXT HANDLE')]/following-sibling::div/div/div/span[data-automation-id="SOMETHING"]

HTML:

<ul>
   <li>
      <div>
          <label>STABLE TEXT HANDLE</label>
      </div>
      <div>
          <div>
              <div>
                  <span></span>
                  <span data-automation-id="something">
                      <div>
                          <div>
                              <div>
                                  DYNAMIC TEXT I WANT TO SCRAPE
                              </div>
                          </div>
                      </div>
                  </span>
                  <span data-automation-id="somethingelse">
                      <div>
                          <div>
                              <div>
                                  DYNAMIC TEXT I WANT TO SCRAPE
                              </div>
                          </div>
                      </div>
                  </span>
              </div>
          </div>
      </div>
   </li>
</ul>

EDIT:

After futher testing, it seems the issue starts with the contains(text(),'STABLE TEXT HANDLE'), which fails to find that particular node (be it the label, or its parent div).

Eleshar
  • 493
  • 4
  • 17
  • Add `//` at the beginning of the XPath expression. See my answer! – Prophet Sep 02 '21 at 13:03
  • @Prophet I am working with Openbots.ai and it allows both ```tag[selector='']``` and ```//tag[@selector='']``` – Eleshar Sep 02 '21 at 13:37
  • So I see finally it worked? – Prophet Sep 02 '21 at 22:17
  • 1
    Yes. It was one of those things that you copy-paste (and check for typos and all) and they do not work at all. You fiddle with a lot of variants, none of them work either, then you reverse back to the original copy-pasted variant... and it just starts working. – Eleshar Sep 03 '21 at 08:01

1 Answers1

1

Please try this:

//label[contains(text(),'STABLE TEXT HANDLE')]/../..//span[@data-automation-id="something"]
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Just to make sure I understand - this goes to the parent ```div```, then to the parent ```li```, and from there it searches for descendant with that particular selector, right? – Eleshar Sep 03 '21 at 10:24
  • Correct, exactly. – Prophet Sep 03 '21 at 10:39