title: Selenium WebDriver throws NoSuchElementException even though the element exists (verified with Firebug/FirePath)
body: <p>I use this code in Selenium WebDriver to extract the value of a certain element on a non-Ajax web page.</p>
  
  <pre><code>    public int getNumberOfPages(WebDriver driver) {
          try {
              webDriverBackedSelenium.click(linkLastPage);
  1               webDriverBackedSelenium.waitForPageToLoad(normalTimeout);
  2               new WebDriverWait(driver, normalTimeoutS).until(ExpectedConditions
                          .presenceOfElementLocated(By.xpath(linkFirstPage)));
  3               return Integer.parseInt(driver.findElement(By.xpath(pathToNumberOfPages))
                          .getText());            
              } catch (NumberFormatException e){
                  e.printStackTrace();
                  webDriverBackedSelenium.click(linkPreviousPage);
                  webDriverBackedSelenium.waitForPageToLoad(normalTimeout);
              } catch (org.openqa.selenium.NoSuchElementException e){
                  e.printStackTrace();
              }
              try {
  4               return Integer.parseInt(driver.findElement(By.xpath(pathToNumberOfPages))
                          .getText());
              } catch (NumberFormatException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              return 0;
          }
  </code></pre>
  
  <p>If I have a breakpoint at (1), open Firebug and insert the XPath the element is found but when I run this I get a NoSuchElementException at both 3 and 4 (if I set breakpoints there, again using FirePath, the element is found as expected).</p>
  
  <p>I tried different kinds if waits, e.g., 1 and 2 above, one at a time as well as both simultaneously, always with the same result.</p>
  
  <p>The timeouts are set to 30 seconds/30 000 milliseconds.</p>
  
  <p>I have read two similar questions</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/24449483/webdriver-findelement-throws-nosuchelementexception-even-though-its-inside-try-c">webdriver findElement throws NoSuchElementException even though its inside try/catch</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/13606134/got-nosuchelementexception-even-though-this-element-exists">Got NoSuchElementException even though this element exists</a></p></li>
  </ul>
  
  <p>but the answers there does not apply to my situation (since I have verified that the element is there with FirePath).</p>
  
  <p>The bl**dy element is there so why doesn't Selenium find it?</p>
  
  <p><strong>XPath</strong></p>
  
  <pre><code>//tr[@class='rgPager']//a[@class='PagerItem'] [@title='Första']
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;a title="Första" class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl04','')" style="display:inline;"&gt;&amp;lt;&amp;lt;&lt;/a&gt;&amp;nbsp;&lt;a title="Föregående" class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl05','')" style="display:inline;"&gt;&amp;lt;&lt;/a&gt;&amp;nbsp;&lt;a class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl06','')" style="display:inline;"&gt;...&lt;/a&gt;&amp;nbsp;&lt;a class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl07','')"&gt;161&lt;/a&gt;&amp;nbsp;&lt;a class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl08','')"&gt;162&lt;/a&gt;&amp;nbsp;&lt;a class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl09','')" style="display:none;"&gt;...&lt;/a&gt;&amp;nbsp;&lt;a title="Nästa" class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl10','')" style="display:none;"&gt;&amp;gt;&lt;/a&gt;&amp;nbsp;&lt;a title="Sista" class="PagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl11','')" style="display:none;"&gt;&amp;gt;&amp;gt;&lt;/a&gt;&amp;nbsp;&lt;br&gt;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl12','')"&gt;A&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl13','')"&gt;B&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl14','')"&gt;C&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl15','')"&gt;D&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl16','')"&gt;E&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl17','')"&gt;F&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl18','')"&gt;G&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl19','')"&gt;H&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl20','')"&gt;I&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl21','')"&gt;J&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl22','')"&gt;K&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl23','')"&gt;L&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl24','')"&gt;M&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl25','')"&gt;N&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl26','')"&gt;O&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl27','')"&gt;P&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl28','')"&gt;Q&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl29','')"&gt;R&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl30','')"&gt;S&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl31','')"&gt;T&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl32','')"&gt;U&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl33','')"&gt;V&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl34','')"&gt;W&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl35','')"&gt;X&lt;/a&gt;&amp;nbsp;Y&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl36','')"&gt;Z&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl37','')"&gt;Å&lt;/a&gt;&amp;nbsp;Ä&amp;nbsp;&lt;a href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl38','')"&gt;Ö&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a class="SelectedPagerItem" href="javascript:__doPostBack('ctl01$cphContent$Quickrank1$ctl00$ctl03$ctl01$ctl39','')"&gt;Alla&lt;/a&gt;
  </code></pre>