use of com.teamdev.jxbrowser.dom.SelectElement in project JxBrowser-Examples by TeamDev-IP.
the class DomSelectOption method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("DOM Select Option");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().on(FrameLoadFinished.class, event -> browser.mainFrame().flatMap(Frame::document).flatMap(Document::documentElement).flatMap(element -> element.findElementById("select-tag")).ifPresent(selectElement -> {
Object[] options = ((SelectElement) selectElement).options().toArray();
((OptionElement) options[2]).select();
System.out.println(selectElement.innerHtml());
}));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><select id='select-tag'>\n" + " <option value=\"volvo\">Volvo</option>\n" + " <option value=\"saab\">Saab</option>\n" + " <option value=\"opel\">Opel</option>\n" + " <option value=\"audi\">Audi</option>\n" + "</select></body></html>");
});
}
Aggregations