WebEngine.load() does not wait until loading has completed. That means if you try to access the web page DOM immediately after load() returns, the page is incompletely loaded.
The right way to do it is to access the DOM after the page has completed loading. The component notifies completion via a listener. It should look like this (from WebEngine documentation):
The other problem in your code is the line:
This code does not find "body" elements in the web page loaded in WebEngine. Instead, what it does is look for a "body" element in the scene's object graph.
When a WebEngine loads a web page, it does not convert the HTML elements in web page into JavaFX Nodes.
One correct way to do what you want is:
posted 6 years ago
I didn' t expect a so detailed response.Thank you for taking the time to write.
I still have a problem.
I use Jsoup library and I use CSS selectors to find DOM elements.
w3c.dom.Document doesn't support CSS selector and finds elements by id or by tagName
How do I find elements in a w3c.dom.Document using CSS rules (like Jsoup document )?
> I use Jsoup library and I use CSS selectors to find DOM elements.
Jsoup has it's own Document model class and does not provide a way to directly translate a w3c document model to it's document model. Also it's APIs only function on it's internal jsoup document model, not the w3c document model supported by WebView. So I do not believe that you would want to use Jsoup in conjunction with a WebView - they aren't really compatible.
> How do I find elements in a w3c.dom.Document using CSS rules (like Jsoup document )?
posted 6 years ago
@John Damien Smith
Thanks for your reply.
executejQuery() method works fine.
I have another problem.
I must press JButton "Change" twice to change tag <a> font color.
How can I fix this problem?
Happily living in the valley of the dried frogs with a few tiny ads.