use of com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN in project JxBrowser-Examples by TeamDev-IP.
the class DomGetAttributes method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><a href='#' id='link' title='link title'>Link</a></body></html>");
});
browser.mainFrame().flatMap(Frame::document).flatMap(Document::documentElement).flatMap(element -> element.findElementById("link")).ifPresent(linkElement -> linkElement.attributes().forEach(DomGetAttributes::print));
}
use of com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN in project JxBrowser-Examples by TeamDev-IP.
the class JsFunctionCallback method main.
public static void main(String[] args) {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
browser.mainFrame().ifPresent(frame -> {
JsObject jsObject = frame.executeJavaScript("window");
if (jsObject != null) {
// Inject JsFunctionCallback into JavaScript and associate it
// with the "window.sayHelloTo" JavaScript property.
jsObject.putProperty("sayHelloTo", (com.teamdev.jxbrowser.js.JsFunctionCallback) arguments -> "Hello, " + arguments[0]);
}
String greetings = frame.executeJavaScript("window.sayHelloTo('John')");
System.out.println(greetings);
});
}
}
use of com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN in project JxBrowser-Examples by TeamDev-IP.
the class XPath method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Evaluate XPath");
frame.getContentPane().add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
Navigation navigation = browser.navigation();
navigation.on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> {
try {
XPathResult result = element.evaluate("count(//div)");
if (result.isNumber()) {
System.out.println("Result: " + result.asNumber());
}
} catch (XPathException e) {
System.out.println(e.getMessage());
}
}));
navigation.loadUrl("https://www.teamdev.com/jxbrowser");
}
Aggregations