How to resolve browser crash issue in JavaFX?

133 views Asked by At

I have a textfield where I need to give Xpath and click on submit button. It has to highlight the corresponding element in the webview below (assume the website is loaded). Here's my code to do that.

webEngine.executeScript(
                                "var elems = document.body.getElementsByTagName(\"*\");"+
                                "for (i = 0; i < elems.length; i++) {"+
                                "elems[i].style.backgroundColor = \"\";"+
                                "}"+
                                "var element = document.evaluate( bridge.getXpath() ,document.body, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;"+
                                "clickController.printId(element, bridge.getXpath());"+
                                "if (element != null) {"+
                                "element.style.backgroundColor = \"#FDFF47\";"+
                        "}");

document.evaluate() method evaluates the given xPath expression (bridge.getXpath() returns the xPath value). If I give a correct Xpath value, it will highlight the element correctly. However, if the Xpath is not correct, then the JavaFX browser is crashing. In the UI, "Java SE has stopped working" popup will appear and ask me to close the program. In backend console, I'm getting "An unrecoverable stack overflow has occurred."

Has anyone encountered this issue? Please share thoughts.

EDIT: Just found out that the issue is with JDK1.7. In JDK1.8 it works properly. Is there a work around in 1.7?

0

There are 0 answers