I am getting null pointer exception when I try to run JavascriptExecutor. Please find my code below. I have followed the following links from stackoverflow
Selenium Javascript executor returns null
driver.executeScript() returns NullPointerException for simple javascript
public void CallApi() {
try {
String result = null;
Thread.sleep(d);
JavascriptExecutor executor = (JavascriptExecutor) driver;
String r1 = Uuid(result);
System.out.println(r1);
String value = (String) (executor.executeScript("return ContentAPI.getReport('" + r1
+ "').registerOutputType('dataset', function(data) { console.log(data) });"));
System.out.println(value);
String js = "function DrillDown() { ContentAPI.getReport('" + r1
+ "').drill('Agency Type', 'Online')}; return DrillDown()";
long value1 = (long) (executor.executeScript(js));
System.out.println(value1);
} catch (InterruptedException e) {
e.printStackTrace();
}
Please find the error below
when I change the value to as per the following I get null returned
String value1 = (String) (executor.executeScript(js));
String js = "function DrillDown() { ContentAPI.getReport('" + r1 + "').drill('Agency Type', 'Online')}; return DrillDown()";don't see any return value in this line.