admin管理员组

文章数量:1291125

I'm trying to get the disabled attr on a button it should be "disabled" but I don't seem to be getting the value. New to angular and protractor!

When I inspect the page this is what HTML I get for the button showing disabled is disabled, like it is on the page:

 <button type="submit" class="button primary inverse" ng-disabled="!ment.$dirty && ment.$valid" disabled="disabled">Save</button>

The protractor test below returns 'Expected null to equal disabled'

    var btnSave = element(by.css('.primary'));
    expect(btnSave.isPresent()).toBeTruthy();

    var attr = element(by.css('.primary')).getAttribute('disabled');

    expect(attr).toEqual("disabled");

When I try I get expected '' to equal disabled.

expect(attr).toEqual("disabled");

Any ideas where I'm going wrong?

Thanks

I'm trying to get the disabled attr on a button it should be "disabled" but I don't seem to be getting the value. New to angular and protractor!

When I inspect the page this is what HTML I get for the button showing disabled is disabled, like it is on the page:

 <button type="submit" class="button primary inverse" ng-disabled="!ment.$dirty && ment.$valid" disabled="disabled">Save</button>

The protractor test below returns 'Expected null to equal disabled'

    var btnSave = element(by.css('.primary'));
    expect(btnSave.isPresent()).toBeTruthy();

    var attr = element(by.css('.primary')).getAttribute('disabled');

    expect(attr).toEqual("disabled");

When I try I get expected '' to equal disabled.

expect(attr).toEqual("disabled");

Any ideas where I'm going wrong?

Thanks

Share Improve this question edited Jan 30, 2016 at 9:52 giri-sh 6,9622 gold badges27 silver badges50 bronze badges asked Jan 29, 2016 at 12:50 thegunnerthegunner 7,16334 gold badges97 silver badges144 bronze badges 1
  • I wonder if isEnabled() (or the Promisified not version of that) work to determine disabled? – Nate Anderson Commented Jul 30, 2017 at 21:57
Add a ment  | 

1 Answer 1

Reset to default 7

getAttribute() function in protractor returns value in the form of promise. So either you have wait until its returned and then perform validation or you can pass in the function to the expectation which in turn resolves the promise. disabled html attribute is a boolean attribute and hence the value that it returns is either true or false. Here's how -

element(by.css('.primary')).getAttribute('disabled').then(function(attr){
    expect(attr).toBe(true);
});

OR

expect(element(by.css('.primary')).getAttribute('disabled')).toBe(true);

Hope it helps.

本文标签: javascriptusing protractor to get the disabled attribute on button not workingStack Overflow