I would like to be able to listen/intercept calls on DomElement
instances to click
and type
so that I can log actions, forward them to another process, modify/reject them, etc. Could this be added?
Specifically, my use case is as follows:
HtmlUnit has one of the best HTML/SVG Java document trees that I can find. e.g. It is fairly up-to-date (unlike org.w3c.dom.html
which doesn't have HTMLOutputElement
, etc.). I need to run some automation in real web browsers but Selenium doesn't provide access to the entire DOM so I can't walk the tree and discover what elements are there and interact with them (I have some very dynamic pages that present form fields in different order on different pages with different options depending on previous input like state, zip code, household members, etc.).
As such, I've written some code to load the page via Selenium WebDriver
and then execute some JavaScript in the remote browser to serialize the remote DOM document and return it along with a list of the associated elements back to the client; now the client has a the serialized XML along with a list of associated WebElement
instances so that once I find an element in the DOM to interact with I can lookup the respective WebElement
instance to control the actual web browser again.
The client parses the xhtml/svg, walks the tree (e.g. using a TreeWalker
) and discovers elements to interact with, looks up the associated WebElement
and sends the action. This process is then repeated until some objective is achieved (e.g. fill in each form on each presented page until a page with a certain title/heading is encountered).
This all runs fairly quick (the interaction with the real browser being the slowest part while the "dumping" of the DOM document, parsing, etc. being fairly fast). What I'd like to do however is not have to lookup a Selenium WebElement
from a DomElement
but use DomElement.click
and DomElement.type
directly and set-up a listener/interceptor to make the WebElement
calls.
In short, I want to use HtmlTextInput
, HtmlPasswordInput
, HtmlSelect
, SvgElement
, etc, etc. as my overall API so that I get full access to the DOM and I get to use a real browser with its JavaScript/CSS processing, etc. but in order to do so I need to be able to hook into the click/type events.