[英]Custom wait for selenium for angular7 application
我們正在使用Selenium Webdriver自動化Angular 7應用程序。 我需要使用Javascript或JQuery的自定義等待,它將等待頁面呈現並等待$ http響應完成。
我已經嘗試過明確的等待,但它們不工作,因為元素加載到頁面上但仍然加載並嘗試了Webdriver,但這也失敗了。
這些可能對您有所幫助。 在訪問任何元素之前,檢查是否完成了Jquery / Angular。
public static boolean isJQueryDone() {
Object jsResponse = tryJavascript("return jQuery.active;");
if (jsResponse instanceof Long) {
return ((Long) jsResponse) == 0;
} else if (jsResponse instanceof String) {
String response = (String) jsResponse;
return (response.startsWith("{\"hCode\"") || response.isEmpty());
} else {
return true;
}
}
public static boolean isAngularDone() {
Object jsResponse = tryJavascript("return window.getAllAngularTestabilities().filter(x=>!x.isStable()).length;");
if (jsResponse instanceof Long) {
return ((Long) jsResponse) == 0;
} else if (jsResponse instanceof String) {
String response = (String) jsResponse;
return response.isEmpty();
} else {
return true;
}
}
public static synchronized Object tryJavascript(String script, Object... args) {
try {
return execJavascript(script, args);
} catch (Exception ignore) {
return "";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.