HtmlUnit webscraping Anchor tag with dropdown link that has JavaScript

Is it possible to click on a link using HtmlUnit when that link has a dropdown list of links when you mouseover the initial link. If you click the initial link nothing happens except for you get list of links that drop down when you mouse over. I would like to click one of the drop down links and grab the web page that is associated with that link.

The problem seems to be that the Anchor has JavaScript and also it is a drop down list. If the Anchor did not have JavaScript and drop down then I would not have any problems.

Here is the pertinent JavaScript Code:

<script language='JavaScript' type='text/javascript'>
function mmLoadMenus(){
 window.mm_menu_0805151542_0 = new Menu("root",211,23,"Arial, Helvetica, sans-serif",11,"#FFFFFF","#FFFFFF","#056CB9","#014D98","left","middle",3,0,1000,-5,7,true,false,true,2,true,false);
  mm_menu_0805151542_0.addMenuItem("View&nbsp;Tax&nbsp;Sales","'TCTaxSaleBrief.asp', '_blank','width=800,height=580,scrollbars=1,resizable=yes,top=50,left=100');");
  mm_menu_0805151542_0.addMenuItem("Registration&nbsp;Renewal&nbsp;Reprint","'vrRenewal.asp', '_blank','width=800,height=580,scrollbars=1,resizable=yes,top=50,left=100');");
  mm_menu_0805151542_0.addMenuItem("Drivers&nbsp;License","'', '_blank');");


Here is the pertinent Anchor:

<a href="#" name="link11" class="nav" id="link10" onmouseover="MM_showMenu(window.mm_menu_0805151542_0,104,0,null,'link11')" onmouseout="MM_startTimeout();">Online Services</a><br />

Here is the snippet of Java Code that I am using to make this work.

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
    String webPage="http://website.html";
    try {
        HtmlPage taxComPage = webClient.getPage(webPage);
        HtmlElement htmlElement = taxComPage.getDocumentElement();
            //HtmlAnchor anchor = taxComPage.getAnchorByText("View Tax Sales");
        //HtmlAnchor htmlAnchor = taxComPage.getHtmlElementById("link10");
        HtmlAnchor anchor = taxComPage.getAnchorByText("Online Services"); 

        HtmlPage page =;

If it is the case that HtmlUnit does not work with JavaScript please let me know!


I understand that there is this function called: mmLoadMenus() which has text that is displayed when moused over but I having issue with how is this function associated with the anchor. In the anchor there is something called MM_showMenu. What is this MM_showMenu, who created it, is this a JavaScript keyword, I don’t see it being defined anywhere. I have searched the whole page, the only place it is mentioned is in the anchor. It seems to be some type of a function with parameters of: window.mm_menu_0805151542_0,104,0,null,’link11′ being passed to it. The only connection that I can make between function mmLoadMenus() and the anchor is that the anchor has mm_menu_0805151542_0 in it. I am not that well versed in JavaScript maybe that is why I am not making a strong connection with the JavaScript function and the anchor.

Leave a Comment