Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if an element is enabled

I need to check with Protractor if a button in my angular application is enabled, for so this is my test:

    it('submit should not be enabled',function() {
      var price = by.name('price'),
          oldCategory = by.name('oldCategory'),
          newCategory = by.name('newCategory'),
          oldPayment = by.name('oldPayment'),
          newPayment = by.name('newPayment'),
          item = by.name('item'),
          submit = by.id('submitButton');
      expect(submit.isEnabled().toBe(false)); 
  });

when I run the test, get this error:

 TypeError: Object By.name("price") has no method 'isEnabled'
like image 502
arpho Avatar asked Jan 29 '14 13:01

arpho


People also ask

How do you know if an element is enabled?

Use the disabled property to check if an element is disabled, e.g. if (element. disabled) {} . The disabled property returns true when the element is disabled, otherwise false is returned.

How do I check if Webelement is enabled in Selenium?

isEnabled() This method verifies if an element is enabled. If the element is enabled, it returns a true value. If not, it returns a false value. The code below verifies if an element with the id attribute value next is enabled.

How do you know if a element is enabled or not using a protractor?

toBe([true|false]); to accurately verify if something is enabled/disabled. If that isn't working for you, there's probably something else going on. Taylor is right, isEnabled() is the correct way to do it.


2 Answers

The parenthesis is misplaced in the expectation :

expect(submit.isEnabled().toBe(false));

it should be :

expect(submit.isEnabled()).toBe(false);

And you misuse the protractor locator :

submit = by.id('submitButton');

it should be :

submit = element(by.id('submitButton'));

You could find a lot of examples in the specs of protractor.

like image 149
gontard Avatar answered Sep 20 '22 16:09

gontard


Try the following:

submit = element(by.id('submitButton'));
like image 44
bigblind Avatar answered Sep 22 '22 16:09

bigblind