title: Expanding a JavaScript menu with WebDriver
body: <p>I am trying to click a button on a webpage with WebDriver which uses JavaScript to expand a menu revealing other links:</p>
  
  <pre><code>&lt;div id="menu"&gt;
  &lt;div id="security_bt" class="advanced_white_close_button" onclick="open_or_close_sub('security');                
  security_open++;"&gt;&lt;b&gt; &lt;span languageCode = "13"&gt;Security&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
  &lt;div id="advanced_bt" class="advanced_white_close_button" onclick="open_or_close_sub('advanced');     
  advanced_open++;"&gt;&lt;b&gt;&lt;span languageCode = "3011"&gt;Advanced Setup&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
  ...etc
  </code></pre>
  
  <p>I have tried using methods suggested on this site including Xpath and CSS</p>
  
  <pre><code>Browser.Driver.FindElement(By.XPath("//div[@id='advanced_bt']/b/span")).Click();
  or
  Browser.Driver.FindElement(By.CssSelector("#advanced_bt &gt; b &gt; span")).Click();
  </code></pre>
  
  <p>and also tried with IJavaScriptExecutor:</p>
  
  <pre><code>            var executor = (IJavaScriptExecutor)webDriver;
          executor.ExecuteScript("arguments[0].click();", element);
  </code></pre>
  
  <p>Neither have worked. The test does not fail to locate the elements, so I'm out of ideas why the can't be clicked. If anyone can shed any light that would be appreciated. Cheers.</p>
  
  <p>Oh and this is the onclick= code:</p>
  
  <pre><code>function open_or_close_sub(name)
  {
  
  var button_name= name+"_bt";
  var sub_name= name+"_sub";
  var open_flag= top.document.getElementById(sub_name).style.display;
  
  close_all_sub(sub_name);/* fold all menus first, except the menu which user click*/
  
  var button_div = top.document.getElementById(button_name);
  var content_length = button_div.getElementsByTagName("span")[0].innerHTML.length;
  if( open_flag == "none")
  {
      settingClass(button_div, content_length, "advanced_white_open_button", top.region_class.white_triple, top.region_class.white_double);
      top.document.getElementById(sub_name).style.display="";
  }
  else
  {
      settingClass(button_div, content_length, "advanced_white_close_button", top.region_class.white_triple, top.region_class.white_double);
      top.document.getElementById(sub_name).style.display="none";
  }
  change_menu_height();
  }
  </code></pre>