Using RanoreXPath to identify row based on the content of two cells

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
pfm
Posts: 2
Joined: Wed May 08, 2019 6:51 am

Using RanoreXPath to identify row based on the content of two cells

Post by pfm » Wed May 08, 2019 7:01 am

I have seen the example "Table item specification" at https://www.ranorex.com/help/latest/ran ... -examples/
It shows how to get the age cell from a table where the row is identified by another cell containing the firstname of a person.
How can i do the same if i need to use both the firstname and the lastname to idenitify the row?

I the following example the outer divs represent rows and the inner divs represents cells.
Each row has three cells: firstname, lastname and age.
How can i identify the age-cell of the row where firstname is Thomas and lastname is Bach?

Code: Select all

<html>
  <body>
    <div>
      <div><span>Thomas</span></div>
      <div><span>Wallace</span></div>
      <div><span>31</span></div>
    </div>
    <div>
      <div><span>Thomas</span></div> <!-- firstname is Thomas -->
      <div><span>Bach</span></div> <!-- lastname is Bach -->
      <div><span>42</span></div> <!-- this is the cell I want to identify -->
    </div>
    <div>
      <div><span>Nicole</span></div>
      <div><span>Bach</span></div>
      <div><span>35</span></div>
    </div>
  </body>
</html>

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Using RanoreXPath to identify row based on the content of two cells

Post by odklizec » Thu May 09, 2019 8:16 am

Hi,

I think you can use something like this:

Code: Select all

//span[@innertext='Nicole']/parent::div//following-sibling::div/span[@innertext='Bach']/parent::div/following-sibling::div/span
The example HTML you posted, is not exactly table, so it's somewhat more complicated to find the information you want. And if the "table" you are using is quite large, with a lot of entries, it may take some time to find desired 'age' element. Plus, if there are more than one person with the same name/surname, it may return multiple age elements, where Ranorex will always pick and use the first one found.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

pfm
Posts: 2
Joined: Wed May 08, 2019 6:51 am

Re: Using RanoreXPath to identify row based on the content of two cells

Post by pfm » Thu May 09, 2019 2:44 pm

I guess something like that would work. Thank you.