I am trying to execute Javascript function called "returnAllLinkTexts()
" on the DOM html page loaded via my Java application. Below line is executed by a Swing Buton.
myscript = browser.executeJavascript("returnAllLinkTexts()").toString(); //Line 407
Once in a while I get the following exception. The Java application does not terminate or crash.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException com.demo.Main$BigButtonListener.actionPerformed(Main.java:407)
I have tried the following to keep retrying about 20 times but it doesn't even reach this point. Exception is raised immediately @ 407.
int st = 0;
while (myscript == null){
myscript = browser.executeJavascript("gogo()").toString(); if (myscript != null) break;
if (shit == 20) break;
sht++;
}
UPDATE:
This is the Javascript function returnAllLinkTexts();
function returnAllLinkTexts(){
var mydata = new Array();
$('a', document).each(function() {
mydata.push($(this).text());
});
return mydata;
}