0

I'm new to Xpath so if this doesn't contain all relevant information apologies & let me know what you need to solve it.

I am trying to find an Xpath to an "expand arrow" element which expands a row in a table. The "expand arrow" element isn't unique so I would like to select it based on text contained in another element on the same row. The layout is as follows:

<td id="__table2-rows-row10-col0">
    <div class="sapUiTableCellFlex">
        <span id="__table2-rows-row10-    treeicon" title="Expand Node" role="button">
        <div id="__hbox27-__clone101">
            <div id="__data70-__clone101">
            <div id="__data71-__clone101">
                <span id="__text47-__clone101" title="sys-admin">sys-admin</span>

I'd like to select the element with title = "Expand Node"

<span id="__table2-rows-row10-    treeicon" title="Expand Node" role="button">

based on the element with title or text = "sys-admin"

<span id="__text47-__clone101" title="sys-admin">sys-admin</span>

I've played around with various options but I can't seem to get it to work. Any ideas would be much appreciated!

Thanks

RCS
  • 23
  • 1
  • 4

2 Answers2

0

To locate the element with title as Expand Node with respect to the element with title or text as sys-admin you can use either of the following Locator Strategies:

  • xpath and title attribute:

    "//span[@title='sys-admin']//ancestor::span[@title='Expand Node']"
    
  • xpath and text() attribute:

    "//span[text()='sys-admin']//ancestor::span[@title='Expand Node']"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your response. My apologies, the indentation in my original snippet was incorrect so I updated the original text. I found a solution in the meantime and added it below. Thanks again. – RCS Feb 28 '20 at 10:27
  • @RCS Indentation of HTML doesn't matters when you can adjust the HTML for testing. My answer would still work as `ancestor` does considers `../../preceding-sibling` too. – undetected Selenium Feb 28 '20 at 10:41
0

I eventually got it to work using the following xpath:

//span[@title='sys-admin']/../../preceding-sibling::span[@title='Expand Node']
RCS
  • 23
  • 1
  • 4