Why Selenium can't find an element that is graphically visible
<p>I'm using Selenium to test an appllication running on a firefox browser, sometimes when i want to click on a button with Selenium, it just don't find it.
I find this strange since i can see the element with my eye. I have already tried multiple method that worked for other exemple like :</p>

<ol>
<li>wait.until(ExpectedConditions.visibilityOfElementLocated(by))</li>
<li>wait.until(ExpectedConditions.presenceOfElementLocated(by));
(i use an xpath in the path variable, and i'm sure he is correct)</li>
<li>Setting a implictlyWait on the driver</li>
<li>Putting Thread.sleep(1000)</li>
</ol>

<p>Then again, i post here because i don't understand why Selenium could not see an element that is diplayed on the browser. An important information that could maybe help you giving me a proper answer is that the html DOM is dynamically generate by websocket triggered by javascript event.</p>

<p>EDIT 1:</p>

<pre><code>&lt;button type="button" class="btn btn-xs btn-block btn-stroke" id="252_button"&gt;
    Delete
&lt;/button&gt;
</code></pre>

<p>The element i'm trying to access. I use an xpath to do it.</p>

<p>It's not in an iframe element.</p>

<p>TO access an element i did this method that is supposed to find and click on it giving the xpath in parameter :</p>

<pre><code>public void findAndClick(String xpath) {
        By by = By.xpath(xpath);
        //wait.until(ExpectedConditions.presenceOfElementLocated(by));
        wait.until(ExpectedConditions.visibilityOfElementLocated(by));

        driver.findElement(by).click();
    }
</code></pre>

<p>EDIT 2:</p>

<p>Here the specific xPath : //div[2]/div/div/div/button
I've found it using the Selenium plugins.</p>

<p>EDIT 3 :</p>

<p>The Exception i'm getting is </p>

<blockquote>
  <p>StaleReferenceElementException: Element not found in cache - perhaps the page has change since it was looked up.</p>
</blockquote>

<p>I went to the <a href="http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp" rel="nofollow">page</a> that explain this Exception, it says that :</p>

<pre><code>The element has been deleted entirely.
The element is no longer attached to the DOM.
</code></pre>

<p>But it can't be, becasue i can see it and click on it manually.</p>