Reputation: 160
How do I propagate the listeners on the next loaded page using UI4J?
For example, The below will navigate to Google and attach to all input
tags a click listener, but I would like to have the binds
reattached after searching and on every page loaded on the "input" tags.
import com.ui4j.api.browser.BrowserEngine;
import com.ui4j.api.browser.BrowserFactory;
import com.ui4j.api.browser.Page;
import com.ui4j.api.dom.Element;
public class AutoWeb {
public static void main(String[] args) {
// get the instance of the webkit
BrowserEngine browser = BrowserFactory.getWebKit();
// navigate to Google
Page page = browser.navigate("http://www.google.com");
// show the browser page
page.show();
// bind the "input" tags
// This should apply for all "input" tags on any page.
for (Element element: page.getWindow().getDocument().queryAll("input")) {
element.bindClick((handler) -> {
System.out.println("Clicked!");
});
}
}
}
If I use an Interceptor
, how do I access the Page Document from the afterLoad()
method in order to re-apply the bindings?
Interceptor interceptor = new Interceptor() {
@Override
public void beforeLoad(Request request) {
}
@Override
public void afterLoad(Response response) {
// Apply the bindings on after load.
}
};
PageConfiguration pageConfiguration = new PageConfiguration(interceptor);
Page page = browser.navigate("http://www.google.com", pageConfiguration);
Upvotes: 0
Views: 432