简体   繁体   中英

how to detect Html elements of webpages rendered in JeditorPane

I am designing a web application testing tool with integrated webbrowser in Java, to implement the browser i used the HTMLEditorKit of JeditorPane which provides bare minimum functionality which is ok for me.

Now I wanna detect all the html elements such as buttons, lists, dropdownList, textfields etc. and record the behaviour of these elements when user interacts with them.(eg User types in textboxes of webpage)

I tried using actionListeners on the JeditorPane to detect events of adding components with no positive result.All the eventsListeners for JeditorPane will not work on the html elements such as textbox(webpage form) displayed in it.

Is there any way i can detect and listen to action of the html elememts(especially web form) rendered in JeditorPane which is dynamically loaded when i supply url.

To render such elements (let's name them controls) EditorKit uses ComponentView and extensions. On paint() ComponentView creates a container - inner class Invalidator. The Invalidator actually contains control from Element attributes.

So after paint() is done you can get list of children of your JEditorPane. I think the list will contains the Invalidators only. And ask each Invalidator about inner component. Thus you'll have list of actual controls created in the JEditorPane.

Then you can add any listeners depending on the component type to register any activity. On each document change event (insert/delete/update) you should recheck changhes in the list after the next paint() and update your data accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM