'elementfinder'类型的参数不能分配给'boolean'类型的参数

时间:2019-05-31 06:07:06

标签: typescript protractor

如果未选中此复选框,我将尝试创建函数,然后在调用此函数时单击它,我收到错误消息 “类型'elementfinder'的参数不能分配给类型'布尔'的参数”

//变量

md5hash_checkbox = element(by.id('md5hash'));
 //To check check box if not selected
  selectCheckBox(checkValue: boolean){
        this.checkValue.isSelected().then(selected => {
            if (selected) {
                console.log(checkValue+': Is Already selected');
            } else {
                this.checkValue.click();
            }
        });

调用类似this.selectCheckBox(this.sha1hash_checkbox)的函数; 得到错误消息“类型为'elementfinder'的参数不能分配给类型为'布尔'的参数”

2 个答案:

答案 0 :(得分:1)

SizedBox( width: 150, child: FlatButton( child: Row( children: [ Text( "Add Note", style: TextStyle(fontSize: 11.0, fontFamily: "Raleway"), ), Image.asset( "images/notesicon.png", width: 20.0, height: 20.0, ) ], ), onPressed: () {}, textColor: Colors.white, color: Color(0xFF226597), shape: OutlineInputBorder( borderSide: BorderSide( style: BorderStyle.solid, width: 1.0, color: Colors.black), borderRadius: new BorderRadius.circular(20.0)), ), ), 适用于isSelected()而非ElementFinder。 您应该这样做:

boolean

答案 1 :(得分:0)

selectCheckBox()希望接受一个web元素,因此您应该将参数类型声明为ElementFinder,而不是boolean。应该是这样的:

selectCheckBox(targetElement: ElementFinder) {
  // only when check box is not selected, then click it
  targetElement.isSelected().then(selected => {
    if (selected) {
      console.log('Already selected');
    } else {
      targetElement.click();
    }
  });
}


md5hash_checkbox = element(by.id('md5hash'));;
selectCheckBox(md5hash_checkbox);