Is there any way to convert IElement  to HtmlElement (Htmlunit)?

I am trying to implement a method that allows me to work in the same way as 
clickByXPath(), and getting hung up on the whole conversion to actually select 
value from the HtmlSelect object:

   public void selectElementByXPath(String xpath, String selectValue) {
        boolean selected = false;
        if (xpath.contains("select")) {
                for (IElement e : getElementsByXPath(xpath)) {
                        try {
                                HtmlSelect s = (HtmlSelect) e;
                                if (s.hasAttribute(selectValue)) {
                                        s.setSelectedAttribute(selectValue, 
true);
                                        selected = true;
                                }
                        } catch (Exception exp) {
                                //do nothing, try othe
                        }
                }
                if (!selected)
                {
                        throw new RuntimeException("selectElementByXPath - 
Could not find select Object \"" + xpath
                                        + "\" with option " + selectValue);
                }
                        
        }
        else
                //throw exception since this is not a select object     
        {
                throw new RuntimeException("Element with xpath \"" + xpath
                                + "\" is not a select object");
        }

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
JWebUnit-users mailing list
JWebUnit-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jwebunit-users

Reply via email to