title: How do I navigate dom elements in puppeteer?
body: <h2>Background</h2>
  
  <p>We are writing some automated end to end tests with puppeteer for the first time. We've been digging through their APIs at great length, but we're stumped and struggling with what feels to us like basic uses for the system.</p>
  
  <h2>The Real Question</h2>
  
  <p>How does puppeteer want us to interact with the elements?</p>
  
  <ul>
  <li>get their attributes</li>
  <li>set stuff on them</li>
  <li>find specific ancestors and descendants of them</li>
  </ul>
  
  <h2>Comments</h2>
  
  <p>What I really want is either a more trimmed API document targeted at our kinds of uses or, even better, a really slick tutorial. We've looked at quite a lot, but we just aren't getting these sorts of answers yet.</p>
  
  <p>What all the guides we have found are doing, that we do not want to do, is manually putting into the code lots and lots of IDs and selectors. I understand why, but for our purposes we want to read from what is on the page and generate our behavior based on it's shape.</p>
  
  <p>Thanks for your time!</p>
  
  <h2>Extra Credit</h2>
  
  <p>How should I actually approach these code snippets? What methods/structures?</p>
  
  <p>Here's one that wants to type a string into all the text inputs, but gets the values for all inputs.</p>
  
  <pre><code>const nodeList = await page.$$('input');
  const result = nodeList.map(async node =&gt; {
      if(node.type === 'text'){
          await node.type('2018');
      }
      return await node.getAttribute('value')
  })
  return result
  </code></pre>
  
  <p>Here's one that wants to type a span label into any child input within that span's parent div.</p>
  
  <pre><code>const nodeList = await page.$$('span');
  const result = nodeList.map(async node =&gt; {
      const parentDiv = node.NearestAncestor('div')
      const inputs = parentDiv.$$('input')
      **Use Code From Above**
  })
  return result
  </code></pre>