2016-01-25 33 views
1

我已经写了下面的代码来检查定位器类型,并根据元素是否可见,我返回元素。我使用适当的值在调用类型(locatorType,value,text)方法上收到错误。量角器:等待一个元素,然后执行动作

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); 
    }; 

下面是正在接收的错误: enter image description here

的webdriver是无法找到的元素,并在其上执行的操作。请提出我错在哪里。

回答

1

独立与体返回等候功能:

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)); 
}; 
+0

它仍然失败,错误:失败: 失败:this.getElement( ...)。sendKeys不是函数 – Abhinav

+0

而在运行代码时,我可以看到它并不是等待元素加载。 – Abhinav

+0

@Abhinav好了,更新了。请检查。 – alecxe

相关问题