Java 量角器测试脚本中禁用按钮的 If 语句
If statement of a disabled button in Java Script for Protractor tests
我有以下问题:
- 我有一个页面,只有当我在文本字段中输入特定值时,“保存按钮”才可以点击。
- 我想做的是检查是否禁用了“保存”按钮,然后我需要在该文本字段中输入一些值。
我以为是这样的:
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)
文档here
所以为了你的目的,你可以使用这样的东西:
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 完全按照您所说的进行操作,但我认为它可以用于其他测试。
我有以下问题:
- 我有一个页面,只有当我在文本字段中输入特定值时,“保存按钮”才可以点击。
- 我想做的是检查是否禁用了“保存”按钮,然后我需要在该文本字段中输入一些值。
我以为是这样的:
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)
文档here
所以为了你的目的,你可以使用这样的东西:
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 完全按照您所说的进行操作,但我认为它可以用于其他测试。