Java Script for Protractor测试中禁用按钮的If语句



我有以下问题:

  • 我有一个页面;保存按钮";只有当我在文本文件中输入某个值时,才可以单击
  • 我想做的是检查如果"保存"按钮被禁用,那么我需要在该文本字段中输入一些值

我想的是有这样的东西:

if (save button is disabled){
enter text inside the filed
click save button
}

我不能做的是将被禁用的保存按钮的值存储到一个布尔变量中。

谢谢!

您可以通过以下方式使用getAttribute()

var yourElement = element(by.id('foo')); //find by id, class or whatever you want
expect(yourElement.getAttribute('disabled')).toBe(true)

此处的文档

因此,为了达到你的目的,你可以使用这样的东西:

if (yourElement.getAttribute('disabled')){
enter text inside the filed
click save button
}

感谢您的解决方案!

我是这样写的:

assertDisabled = function(){
assertionsPage.assertAttribute(myProfilePage.saveButton,'disabled','true')
return true
}
var value = assertDisabled()
console.log(value)
if (value==true){
myProfilePage.pinCodeValue.sendKeys(1234)
}

assertAttribute完全按照你说的做,但我认为它可以在其他测试中使用。

最新更新