title: Python - How to parse xml response and store a elements value in a variable?
body: <p>I am getting the XML response from the API call.</p>
  <p>I need the &quot;testId&quot; attribute value from this response. Please help me on this.</p>
  <pre class="lang-py prettyprint-override"><code>r = requests.get( myconfig.URL_webpagetest + &quot;?url=&quot; + testurl + &quot;&amp;f=xml&amp;k=&quot; + myconfig.apikey_webpagetest )
  xmltxt = r.content
  print(xmltxt)
  testId = XML(xmltxt).find(&quot;testId&quot;).text
  r = requests.get(&quot;http://www.webpagetest.org/testStatus.php?f=xml&amp;test=&quot; + testId )
  </code></pre>
  <p>xml response:</p>
  <p><a href="https://i.stack.imgur.com/XYQW2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XYQW2.png" alt="screenshot of xml response" /></a></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;response&gt;
      &lt;statusCode&gt;200&lt;/statusCode&gt;
      &lt;statusText&gt;Ok&lt;/statusText&gt;
      &lt;data&gt;
          &lt;testId&gt;180523_YM_054fd7d84fd4ea7aed237f87289e0c7c&lt;/testId&gt;
          &lt;ownerKey&gt;dfc65d98de13c4770e528ef5b65e9629a52595e9&lt;/ownerKey&gt;
          &lt;jsonUrl&gt;http://www.webpagetest.org/jsonResult.php?test=180523_YM_054fd7d84fd4ea7aed237f87289e0c7c&lt;/jsonUrl&gt;
      &lt;/data&gt;
  &lt;/response&gt;
  </code></pre>
  <p>The following error is produced:</p>
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File &quot;/pagePerformance.py&quot;, line 52, in &lt;module&gt;
      testId = XML (xmltxt).find(&quot;testId&quot;).text
  AttributeError: 'NoneType' object has no attribute 'text'
  </code></pre>