How to loop through element children using etaoin?

Anyone have experience using etaoin?

I have it successfully logging in and loading my desired page. However, I’m at a loss for how I can identify an element and loop it’s children to extract data from the children’s children. The simiplfied html looks something like this:

<div id="content-main">
  <div id="row-1" class="content-row">  <!-- first row / child
    <div class="row-responsive">
     <div class="col-responsive"> <!-- first column
      <div class="row-responsive">
       <a href="">
         <img src="" alt="" /> <!-- I want img.src and img.alt
       </a>
      </div>
     </div>
    <div class="col-responsive"> <!-- second column
      <div class="row-responsive">
        <div class="col-responsive">
          <span>
           <ul>
            <li></li>
            <li>
             <span>
               <a>
                 <span></span> <!-- need innerText here
               </a>
             </span>
            </li>
           <ul>
         </span>
        </div>
      </div>
    </div>
    </div>
  </div>
  <div id="row-2" class="content-row">  <!-- second row / child
  </div>
</div>

If I do a query on the content-main:

(query driver {:tag :div :id "content-main"})

It returns a guid "e73ca52d-410f-4d64-8113-1536737eb781".

I just need to know how to loop through the content-main children, then I can probably use xpath selectors for those children since some of the data is deeply nested.

Any ideas?

Yes, it’s brilliant.

There are essentially two ways to find something:

  • via a query
  • via an “element”

Most etaoin functions accept a query, or a number of queries, and a handful of those have an -el suffix and accept an “element” instead of a query. I am quoting “element” because it is actually the GUID that you have correctly identified above.

Now to find children of an element, you would call:

(children driver element {:tag :div})

This will return a seq of of child elements, and you can query each of those, e.g. using any of the get-element-* functions.

This means you need to find the element first, as you have already done, and then find its children. There doesn’t seem to be any way to do it directly via a query. Oh and you can plug in any query you like for the children, it doesn’t have to be {:tag :div}.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.