title: java selenium element found but one click does not work
body: <p>I have a piece of selenium code to look for a certain element and afterwards to click on this same element. The element is found, but after that, the click does not seem to do the trick. Here is the code for finding the element (unfortunately using xpaths, because there are no id's and it uses a lot of selfmade methods):</p>
  
  <pre><code>String taakButton = "Start taak button";
  String xpathButton = "//td[contains(text(),'" + datumhelper.formateerDatumVoorFlowAanmaakdatum(SoapHelper.datumVoorAanvraag5SpaarrekeningSns) + "')]/following-sibling::*[4]/button";
  WebElement startButton = selenium.searchForElementByXpathWithoutSwitchToFrame(xpathButton, taakButton);
  </code></pre>
  
  <p>I use the above String xpathButton to store a WebElement in a variable, after that I pass the WebElement to a method in a different class:
  The searchForElementByXpathWithoutSwitchToFrame looks for the element and verifies if it is found.</p>
  
  <pre><code>WebElement startTaakButton = selenium.searchForElementByXpathWithoutSwitchToFrame(xpathStartTaakButton, taakButton);
  </code></pre>
  
  <p>The element is found, now click on it :</p>
  
  <pre><code>selenium.klikStartOfInzienTaak(startTaakButton, xpathStartTaakButton);
  </code></pre>
  
  <p>The klikStartOfInzienTaak method, which performs the click looks like this:</p>
  
  <pre><code>public void klikStartOfInzienTaak(WebElement webElementToBeClicked, String xpathToBeClicked) throws InterruptedException {
  Actions action = new Actions(driver);
  //check to see if element is not null
  Assert.assertNotNull("WebElement 'startOfInzienTaak' niet gevonden", webElementToBeClicked);
  //Thread.sleep(2500);
  //I use Action doubleClick in the hope that would work.       
  action.moveToElement(webElementToBeClicked).doubleClick().build().perform();
  </code></pre>
  
  <p>I also used regular <code>driver.click().</code> It seems the element is found because it does not give a <code>NoSuchElementException</code> and I see the focus is on the element to be clicked, but nothing happens:
  <a href="https://i.stack.imgur.com/a1VzO.png" rel="nofollow noreferrer">Button to be clicked</a> </p>
  
  <p>When I uncomment the Thread.sleep it works, but I don't want to be using Thread.sleep.</p>
  
  <p>As you can see in the image below with the loading image, the page seems to be (re)loading again after the element was already found and clicked on. Thats why the <code>Thread.sleep</code> works:
  <a href="https://i.stack.imgur.com/PT1WO.png" rel="nofollow noreferrer">Button found and clicked but page (re)loading</a></p>
  
  <p>Does anybody know what to do in order for me to remove the thread.sleep? Selenium has to somehow wait again for the page to reload again although the element is already found?</p>