title: Using Playwright for Python, how do I select (or find) an element?
body: <p>I'm trying to learn the Python version of Playwright. See <a href="https://github.com/microsoft/playwright-python#documentation" rel="nofollow noreferrer">here</a></p>
  <p>I would like to learn how to locate an element, so that I can do
  things with it. Like printing the inner HTML, clicking on it and such.</p>
  <p>The example below loads a page and prints the HTML</p>
  <pre><code>from playwright import sync_playwright
  
  with sync_playwright() as p:
      browser = p.chromium.launch(headless=False)
      page = browser.newPage()
      page.goto('http://whatsmyuseragent.org/')
      print(page.innerHTML(&quot;*&quot;))
      browser.close()
  </code></pre>
  <p>This page contains an element</p>
  <pre><code>&lt;div class=&quot;user-agent&quot;&gt;
      &lt;p class=&quot;intro-text&quot;&gt;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4238.0 Safari/537.36&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Using Selenium, I could locate the element and print it's content like this</p>
  <pre><code>elem = driver.find_element_by_class_name(&quot;user-agent&quot;)
  print(elem)
  print(elem.get_attribute(&quot;innerHTML&quot;))
  </code></pre>
  <p>How can I do the same in Playwright?</p>
  <p>#UPDATE# - Note if you want to run this in 2021+ that current versions of playwright have changed the syntax from CamelCase to snake_case.</p>