title: selenium and clicking an "a" with href=javascript
body: <p>I'm trying to click a link and am having difficulties. The relevant HTML code is:</p>
  
  <pre><code>&lt;div id="adHocAddDocDiv" style="display: block;"&gt;
      &lt;a href="javascript:hideDiv();" style="color:#000"&gt;
          Close window
      &lt;/a&gt;
      &lt;table border="0"&gt;
          &lt;tbody&gt;&lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>For code, I have:</p>
  
  <pre><code>driver.findElement(By.xpath("//*[@id='adHocAddDocDiv']/a")).click();
  </code></pre>
  
  <p>This does find the correct element, however it doesn't seem to execute the JavaScript to close the window that happens if I manually click the link.  Any ideas?</p>
  
  <p>UPDATE:  Here is the code that finally worked:</p>
  
  <pre><code>WebElement element = driver.findElement(By.xpath("//[@id='adHocAddDocDiv']/a"));
  JavascriptExecutor executor = (JavascriptExecutor)driver;
  executor.executeScript("arguments[0].click();", element);
  </code></pre>