我正在尝试按以下方式点击元素,但收到错误时说:
Failed: Cannot read property 'click' of undefined
代码:
'use strict;'
var PresentPage = function(){
let PresentPageTitle = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/matanot/form/div[2]/h4"));
let UserPhone = element(by.id("tel"));
let Email = element(by.id("email"));
var AresForPresents = element(by.xpath("//*[@id='verticalRadioGrp']/div/select")).all(by.tagName("option")).then(function(options)
{
return options;
});
this.SelectAreaToGetPresent = function()
{
AresForPresents[3].click();
};
};
module.exports = new PresentPage();
编辑: 在函数中使用它时可以正常工作。
this.SelectAreaToGetPresent = function()
{
element(by.xpath("//*[@id='verticalRadioGrp']/div/select")).all(by.tagName("option")).then(function(options)
{
options[3].click();
});
答案 0 :(得分:1)
看起来您的代码无法处理承诺。
var AresForPresents = element(by.xpath("//*[@id='verticalRadioGrp']/div/select")).all(by.tagName("option"));
this.SelectAreaToGetPresent = function()
{
AresForPresents.then((options)=> { options[3].click(); });
};
否则,您需要async/await。
var AresForPresents;
this.SelectAreaToGetPresent = async ()=>
{
AresForPresents = await element(by.xpath("//*[@id='verticalRadioGrp']/div/select")).all(by.tagName("option"));
AresForPresents[3].click();
};