0

我正在设计一个在 Java 中集成 webbrowser 的 web 应用程序测试工具,为了实现我使用 JeditorPane 的 HTMLEditorKit 的浏览器,它提供了对我来说可以的最低限度的功能。

现在我想检测所有 html 元素,例如按钮、列表、下拉列表、文本字段等,并记录用户与这些元素交互时的行为。(例如,网页文本框中的用户类型)

我尝试在 JeditorPane 上使用 actionListeners 来检测添加没有正面结果的组件的事件。JeditorPane 的所有 eventsListeners 都不适用于其中显示的文本框(网页表单)等 html 元素。

有什么方法可以检测和监听在 JeditorPane 中呈现的 html elememts(尤其是 web 表单)的动作,当我提供 url 时动态加载。

4

1 回答 1

0

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.

于 2010-12-24T07:57:30.343 回答