我编写了下面的代码来检查定位器类型,并根据元素是否可见,我返回元素。我在使用适当值的调用类型(locatorType,值,文本)方法时收到错误。
this.type = function(locatorType,value,text){
this.getElement(locatorType,value).sendKeys(text)
};
this.getElement = function(locatorType,value){
if(locatorType=='model'){
console.log(locatorType)
console.log(value)
return this.waiterFunc(element(by.model(value)));
}
else if(locatorType=='xPath'){
return this.waiterFunc(element(by.xPath(value)));
}
else if(locatorType=='buttonText'){
return this.waiterFunc(element(by.buttonText(value)));
}
};
this.waiterFunc = function(element){
console.log('In waiterfunc')
//console.log(element.getText())
browser.wait(function() {
return this.isVisible(element).then(function(){
return element;
})
})
};
this.isVisible = function(element){
return EC.visibilityOf(element);
};
WebDriver 无法找到该元素并对其执行操作。有错误的地方请指出。
最佳答案
将等待函数与元素返回分开:
this.getElement = function(locatorType, value) {
var elm;
if (locatorType == 'model') {
elm = element(by.model(value));
this.waiterFunc(elm);
}
else if (locatorType == 'xPath') {
elm = element(by.xpath(value)); // also renamed xPath -> xpath
this.waiterFunc(elm);
}
else if (locatorType == 'buttonText') {
elm = element(by.buttonText(value));
this.waiterFunc(elm);
}
return elm;
};
在这种情况下,waiterFunc
会变得更简单:
this.waiterFunc = function(element){
browser.wait(this.isVisible(element));
};
关于javascript - Protractor :WAITING一个元素,然后执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34993176/