当我引用'elements'中定义的选择器时,它在第二个语句中无法识别,但在第一个语句中按预期工作。
const vmDetailCmds = {
command(vm_name,actionButton){
....
//reference @activityTable work as expected here
this.expect.element("@activityTable").to.be.present.before(1000);
//reference @activityTable can not be reconginzed here
this.api.elements("css selector","@activityTable", function(result){
var count = result.value.length;
console.log(result);
console.log("count:"+count);
......
});
....
},
};
module.exports = {
commands:[vmDetailCmds],
elements: {
....
activityTable: "ul[aria-label='List Use arrow keys to navigate']>li[aria-label='Box']";
....
},
};
以下是打印出来的结果,有什么想法吗?
√ Expected element <ul[aria-label='List Use arrow keys to navigate']>li[aria-label='Box']> to be present - element was present in 36ms
{ status: -1,
value: { message: 'invalid selector: An invalid or illegal selector was specified\n (Session info: chrome=60.0.3112.113)\n (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.14393 x86_64)' },
errorStatus: 32,
error: 'Argument was an invalid selector (e.g. XPath/CSS).' }
count:undefined
答案 0 :(得分:0)
当您致电 this.api.elements(...)时,您指的是浏览器中的元素。
activityTable 是仅在您自己的页面对象中可用的元素,并且不存在于浏览器中。
相反,你必须将整个元素放在那里:
this.api.elements("css selector","ul[aria-label='List Use arrow keys to navigate']>li[aria-label='Box']", function(result){
...
}