Re: HttpUnit and XPath

Morgan Christiansson <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <1150470580.14830.7.camel@localhost>
There's not really any easy way to convert a node in the DOM tree to a
httpunit object afaik. Httpunit essentially wrappes the DOM objects with
it's own Web* objects but the DOM tree can't do it the other way around.

1. Maybe if you checked all WebLink objects and compared them with your
Node object.

2. Or you manually extract the link from the Node object and request it
manually, httpunit can handle the relative links for you. Won't work if
you want javascript though.

3. If you don't mind hacking the source you might be able to use a
HashMap to look up httpunit objects from Node objects.

Might be other ways to do it but these are the ones that sprang to mind
first.

Regards,
Morgan

On Fri, 2006-06-16 at 15:07 +0200, Julien Henry wrote:
> Hi,
> 
> I would like to use HttpUnit and XPath. I found this page : 
> http://idiacomputing.com/moin/HtmlTestingUsingXpath
> It's now possible for me to check if an element is present thanks to 
> xpath. But now, I want to click on a link specified by it's XPath.
> 
> I have this code :
> private Object getElementByXPath(String xpath) {
>         try {
>             Document rootNode = getResponse().getDOM();
>             XPath xpathObject = makeXpath(xpath);
>             return xpathObject.selectSingleNode(rootNode);
>         } catch (SAXException e) {
>             throw new RuntimeException(e);
>         } catch (JaxenException e) {
>             throw new RuntimeException(e);
>         }
>     }
> 
>     public void clickElementByXPath(String xpath) {
>         Object o = getElementByXPath(xpath);
>         if (o instanceof Node) {
>             ??????????????
>         }
>         else {
>             throw new RuntimeException("Don't know how to click on this 
> element");
>         }
>     }
> So I get a Node thanks to XPath, but I don't know how to make httpunit 
> parse it and click on it.
> 
> Any idea ?
> 
> Thanks
> 
> Julien Henry
> 
> This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.
> 
> 
> 
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.