Search code examples
javajxbrowser

JxBrowser How to get value from a html node within java


Hello guys I am trying out the jxBrowser component and I am unable to the value of selected html component...

List<DOMElement> paragraphs = divRoot.findElements(By.cssSelector("p"));
            for (DOMElement paragraph : paragraphs) {
                System.out.println("paragraph.getNodeValue() = " +
                        paragraph.getNodeValue());
            }

I am able to find paragraphs.. But can't get their node's value.. or simply <p>I cant get this value<p/> The code must be okay because its just a pure copy of their own sample code: here

So my question is... What have I done wrong? It seems properly imported.. I am using library version 6.19.1 on a macbook. ( And I even tried it on a windows 10 with same result.. )

Or if there is other java browser solution with similar functions.. What I need is to load a page, get some values out of some divs and then simulate click.


Solution

  • DOMElement.getNodeValue() returns the value of this node, depending on its DOMNodeType. The text you are trying to get is a children node for the

    node, so you need to get it with the following code paragraph.getChildren().get(0).

    So, the final code will look like the following:

    for (DOMElement paragraph : paragraphs) {
        System.out.println("paragraph.getNodeValue() = " +
        paragraph.getChildren().get(0).getNodeValue());
    }