我正在尝试等待砌体完全用Java加载此代码
String javaScript = "function defer() {"
+"if (window.jQuery.masonry)"
+"{ return true }"
+"else"
+"{ return false }"
+"}; defer()";
boolean isMasonryLoaded=false;
while(!isMasonryLoaded)
{
isMasonryLoaded = (boolean)(((JavascriptExecutor)driver).executeScript(javaScript));
}
但是我在
while(!isMasonryLoaded)
处得到NullPointerException有任何想法吗 ?
最佳答案
可能是您的脚本函数defer()
在调用前未定义,您应该尝试使用executeAsyncScript
,如下所示:-
String javaScript = "var callback = arguments[0];"+
"function defer() {if (window.jQuery.masonry){ "+
"callback(true) }else{ callback(false) }}; defer()";
boolean isMasonryLoaded=false;
while(!isMasonryLoaded)
{
isMasonryLoaded = (boolean)(((JavascriptExecutor)driver).executeAsyncScript(javaScript));
}
希望能帮助到你..:)