天天看點

Selenium WebDriver施用經驗雜記

 利用javascript注入,來讀取不同ajax調用架構的ajax request status,一直等到ajax調用全部傳回才開始分析操作dom元素

  示範代碼如下:

protected void syncajaxbyjquery(string timeout) {

boolean issucceed = false;

try {

"selenium.browserbot.getcurrentwindow().jquery.active == 0", timeout);

issucceed = true;

} catch (seleniumexception se) {

log.error(se);

} catch (exception re) {

throw new runtimeexception(re.getmessage());

}

operationcheck(issucceed);

protected void syncajaxbyprototype(string timeout) {

selenium.waitforcondition(

"selenium.browserbot.getcurrentwindow().ajax.activerequestcount == 0",

timeout);

protected void syncajaxbydojo(string timeout) {

"selenium.browserbot.getcurrentwindow().dojo.io.xmlhttptransport.inflight.length == 0",

other tips

  加載iedriver的時候,通常會因為相容模式的設定問題,而無法啟動,嘗試在建立iedriver對象的時候,加入合适的參數設定:

desiredcapabilities iecapabilities = desiredcapabilities.internetexplorer();

iecapabilities.setcapability(internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains, true);

return new internetexplorerdriver(iecapabilities);

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀