If statement of a disabled button in Java Script for Protractor tests

Tags: ,



I have the following issue:

  • I have a page where the “Save button” becomes clickable only when I enter a certain value inside a text filed.
  • What I want to do is to check that if the Save button is disabled, then I need to enter some value in that text field.

What I thought is to have something like this:

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

What I couldn’t do is to store the value of the save button being disabled into a Boolean variable.

Thank you!

Answer

You can use getAttribute() int his way:

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

Docs here

So to your purpose you can use something like this:

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


Source: stackoverflow