Thanks Thiago, I will look into your suggestion, I actually think htmlparser is 
even already used somewhere else in the application.
I'm actually using Selenium WebDriver, and it's true, it's beautifullly suited 
for this.


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiag...@gmail.com] 
Sent: Thursday, April 6, 2017 18:09
To: Tapestry users <users@tapestry.apache.org>
Subject: Re: Creating an org.apache.tapestry5.dom.Document from client-side 
page source

Isn't this scenario better suited for a web testing tool like Selenium or 
WebDriver?

If you really, really want to parse HTML into Tapestry DOM elements, you can 
use the nu.validator.htmlparser library, which parses HTML using HTML5 rules 
and presents itself as a SAX parser. You'll need to subclass 
org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM elements inside 
its methods. Then you can do whatever you want with it, including using XPath 
through tapestry-xpath, which I cannot recommend enough.

On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <d...@amc.dk> wrote:

> Hi everybody
>
> I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in 
> that test I retrieved the whole client-side page source into a String. 
> It's a regular HTML page generated by Tapestry. Nothing special about 
> it, it starts with
>
> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml";><head> ....
>
> and it ends with
>
> ...... </body></html>
>
> I need to create an org.apache.tapestry5.dom.Document instance from 
> that page source, manipulate its DOM, turn the resulting Document back 
> into a string, and make assertions about this string.
>
> My problem is only that I can't seem to be able to do the first step, 
> that is create the Document instance from my String containing the page 
> source.
>
> I tried MarkupWriter (its write() and writeRaw() methods):
>
>        MarkupWriter writer = new MarkupWriterImpl();
>
>        writer.write(htmlText); // writer.writeRaw(htmlText);
>
>        Document document = writer.getDocument();
>
> but then document does not contain the DOM elements that were in 
> htmlText (which is the String containing the page source), and
> document.getDocumentElement() returns null.
>
> I have tried other variations still with MarkupWriter, Document and 
> all their methods that seemed related, but I got nothing.
>
> I'm sure I'm just missing something trivial. Does anyone know ?
>
> If possible I'd prefer a Tapestry solution, where the created object 
> is an org.apache.tapestry5.dom.Document, but if it's necessary to get 
> a org.w3c.dom.Document instead, or to use something else outside 
> Tapestry, I would still go for it.
>
> Thanks in advance.
>
>


--
Thiago

Reply via email to