我正在使用 casperjs 来获取页面上的所有 jquery ui 选项卡并单击每个选项卡。问题是选项卡是动态加载的,并且似乎永远不会从“正在加载...”状态切换。我尝试过使用 casperwait()
函数甚至waitWhileSelector(
) 函数,但似乎都不起作用:
function getActiveTab () {
var active_tab = $('#tabs>ul').find('li.ui-tabs-selected').text();
console.log("Active tab: " + active_tab);
return active_tab;
}
function clickTabs (tabs) {
this.each(tabs, function(casper, tab_name, i){
var child_number = i + 1;
var tab_selector = "#tabs>ul>li:nth-child(" + child_number + ")>a";
console.log(tab_selector);
// this.thenClick(tab_selector).waitWhileSelector('#tabs>ul>li.ui-state-processing', function(){
this.thenClick(tab_selector, function(){
var this_tab = this.evaluate(getActiveTab);
});
});
}
它似乎适用于第一个选项卡(因为它是在页面加载时加载的),但所有其余选项卡都返回“正在加载”:
------ snip passed tests ------
#tabs>ul>li:nth-child(1)>a
#tabs>ul>li:nth-child(2)>a
#tabs>ul>li:nth-child(3)>a
#tabs>ul>li:nth-child(4)>a
#tabs>ul>li:nth-child(5)>a
#tabs>ul>li:nth-child(6)>a
#tabs>ul>li:nth-child(7)>a
#tabs>ul>li:nth-child(8)>a
#tabs>ul>li:nth-child(9)>a
remote message caught: Active tab: Host Allocation
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#disk_pools_table').dataTable')
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#vvol_groups_table').dataTable')
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#arrayCablesTable').dataTable')
remote message caught: Active tab: Loadingâ¦
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#fa_information_table').dataTable')
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#zoning_table').dataTable')
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#pool_mismatch_table').dataTable')
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#other_information_table').dataTable')
remote message caught: Active tab: Loadingâ¦
Page Error: TypeError: 'undefined' is not a function (evaluating '$('#arrayIPs').dataTable')
remote message caught: Active tab: Loadingâ¦
FAIL 12 tests executed in NaNs, 11 passed, 1 failed.
当我使用 waitWhileSelector 时,它会在第一次单击后超时。大多数选项卡动态加载带有 dataTables 对象的脚本标记,并且似乎永远不会加载表对象或未加载数据表库?我是否必须将该库注入评估方法,或者页面中的标签是否应该将其拉入?
我将不胜感激任何帮助隔离此测试中发生的事情。