Iladarsda
Iladarsda

Reputation: 10696

Protractor: find hidden input element by attribute value

How do I go about locating & getting a value for an element like the following?

<input type="hidden" title="username" value="joe.doe">

Any suggestions much appreciated.

Upvotes: 7

Views: 9534

Answers (2)

Aakash
Aakash

Reputation: 23805

If you are trying to access an element with data-* attributes as we would do in Bootstrap, we can select such elements as follows:-

var loginBtn = $('a[data-target="#login-modal"]');

This is same as the accepted answer except that it has "" around #login-modal. Without the "", it doesn't work.

Good Luck.

Upvotes: 0

Leo Gallucci
Leo Gallucci

Reputation: 16722

var userNameElm = $('input[title=username]');

it('is present but invisible', function() {
    expect(userNameElm.isPresent()).toBeTruthy();
    expect(userNameElm.isDisplayed()).toBeFalsy();
});

it('should have proper value attribute', function() {
    expect(userNameElm.getAttribute('value')).toEqual('joe.doe');
});

Upvotes: 16

Related Questions