Need to write a smart RanoreXPath

Ask general questions here.
kkmmaa
Posts: 2
Joined: Thu Nov 08, 2012 3:17 pm

Need to write a smart RanoreXPath

Post by kkmmaa » Thu Nov 08, 2012 3:39 pm

Hi,

I need to write a smart RanoreXPath that will find the div of text Flight 2242 and will hit <div class="x-list-disclosure "/> of the following code.

Current solution:
.//div[@innertext='Flight 2242']/../../../../div[2]


But, I need a smarter one that does not need to travel by hard coded parents like this /../../../../
Something, theoretically,


.//div[@innertext='Flight 2242']/((../)*div[@class~'x-list-disclosure'])*


Or, I need to write a user code function that can travel to parent and look for the right div child? Thanks for any comments.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<div id="ext-component-6" class="x-list-container">
  
  <div class="x-list-item" id="ext-element-168">
    
    <div class="x-list-item-label">
      
      <div class="list-item-main">
        
        <div class="top gs-top">
          
          <div class="left clr-white">[b]Flight 2242[/b]</div>
          
          <div class="right clr-white gs-top-right-due">
            Time remaining is 
            
            <span class="em-time">6:30</span>
            
          </div>
          
        </div>
        
        <div class="bottom">
          
          <div class="cell2 left">
            
            <table class="tbl">
              
              <tbody>
                
                <tr>
                  
                  <td class="bdr-bottom">737-200 - 245</td>
                  
                </tr>
                
                <tr>
                  
                  <td class="bdr-bottom">19 Planned Items (SERVICE)</td>
                  
                </tr>
                
                <tr>
                  
                  <td>4 Open Faults / 1 MEL Deferrals</td>
                  
                </tr>
                
              </tbody>
              
            </table>
            
          </div>
          
          <div class="cell2 center">
            
            <table class="tbl">
              
              <tbody>
                
                <tr>
                  
                  <td>
                  </td>
                  
                  <td class="cell3 fnt-small center">Arrival</td>
                  
                  <td class="cell3 fnt-small center">Departure</td>
                  
                </tr>
                
                <tr>
                  
                  <td class="cell3 fnt-small right">Time</td>
                  
                  <td class="cell3 center bdr-bottom">13:15</td>
                  
                  <td class="cell3 center bdr-bottom bdr-left">19:45</td>
                  
                </tr>
                
                <tr>
                  
                  <td class="cell3 fnt-small right">Gate</td>
                  
                  <td class="cell3 center">34</td>
                  
                  <td class="cell3 center bdr-left">15</td>
                  
                </tr>
                
              </tbody>
              
            </table>
            
          </div>
          
        </div>
        
      </div>
      
    </div>
    
    [b]<div class="x-list-disclosure "/>[/b]
    
  </div>

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Need to write a smart RanoreXPath

Post by Support Team » Fri Nov 09, 2012 10:42 am

Hello,

Yes, can use the 'ancestor' operator to get the parents and grandparents of the current node.

For example:
.//div[@innertext='Flight 2242']//ancestor::div[@class~'x-list-disclosure']

You can find more information about RanoreXPath in the section Layout of Advanced RanoreXPath Editor in our user guide.

Regards,
Bernhard

kkmmaa
Posts: 2
Joined: Thu Nov 08, 2012 3:17 pm

Re: Need to write a smart RanoreXPath

Post by kkmmaa » Fri Nov 09, 2012 3:31 pm

Thank you for the reply. I am naive about it. But, can you please clarify, is C is an ancestor of I

Code: Select all

      |
      G
     / \
    E   F
   /     \
  C       H
            \
             I


User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Need to write a smart RanoreXPath

Post by Support Team » Mon Nov 12, 2012 5:59 pm

Hello,

You are completely right, I made a little mistake in the RxPath. The following RxPath should work.

.//div[@innertext='Flight 2242']//ancestor::node()/div[@class~'x-list-disclosure']

Thank you!

Regards,
Bernhard