Skip to content Skip to sidebar Skip to footer

Javascript Executor Gives Null When Trying To Access Window.propertyname

I can see these many properties in console if I type window in Chrome console and hit enter. But when I am trying to access same properties via Javascript Executor it gives me null

Solution 1:

I found the solution. The mistake I was doing, I was not returning function in JS snippet. I added one more line return show_homepage(); and it worked.

String location = "function show_homepage() {"+
            "var homepage = window.location.origin;"+
            "return homepage;"+
            "}"+
            "return show_homepage();";
Object str = js().executeScript(location, "");
System.out.println(str.toString());

Post a Comment for "Javascript Executor Gives Null When Trying To Access Window.propertyname"