title: How to get the only PDF url from web page?
body: <p>I am trying to get some DOM elements using Selenium and I am doing all of this using Java but I am getting this Error when trying it out:</p>
  <pre><code>Exception in thread &quot;main&quot; org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  </code></pre>
  <p>I am still a newbie in all this but the code I am using to retrieve the DOM element is:</p>
  <pre><code> driver.get(&quot;https://www.qp.alberta.ca/570.cfm?frm_isbn=9780779808571&amp;search_by=link&quot;);
  String pagePdfUrl = driver.findElement(By.xpath(&quot;//img[@alt='View PDF']//..//parent::a&quot;)).getAttribute(&quot;href&quot;);
  </code></pre>
  <p>I believe the error is that it cannot find the XPath given although this xpath exists. Any help would be appreciated.</p>
  <p>Thank you.</p>