Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify an element using getText() returns empty string when using typeahead

I am using Protractor to run e2e tests, but am unable to verify the text of an element using getText(). Protractor returns:

Expected '' to equal 'Joe Smith'.

Here is the code:

<span class="input-group" style="padding: 40px;">
 <input tabindex="0" class="form-control ng-valid ng-dirty ng-
 valid-parse ng-touched" id="requesterSearchInput" aria-expanded="false"
 aria-invalid="false" aria-owns="typeahead-6604-1028" aria-
 autocomplete="list" type="text" placeholder="Enter a Requester name" ng-
 model="searchText" typeahead-loading="loadingLocations" typeahead-wait-
 ms="500" typeahead-min-length="1" typeahead-on-
 select="OnRequesterSelect($item)" typeahead-template-
 url="requesterTypeAheadTemplate.html" typeahead="rdata for rdatas in 
 GetRequesters($viewValue)"></input>

In my test script, I have:

element(by.id('requesterSearchInput')).click();
browser.actions().sendKeys('Joe Smith').perform();
expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');

However the last line fails with:

 Expected '' to equal 'Joe Smith'.

I have made several attempts at solving this problem and none have worked. Here are my attempts:

Attempt 1:

expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');

Attempt 2:

expect(element(by.id('requesterSearchInput')).getAttribute("aria-hidden")).toEqual('Joe Smith');

Attempt 3:

expect(element(by.id('requesterSearchInput')).getAttribute("innerText")).
    toEqual('Joe Smith');

Attempt 4:

var previousEntry = element(by.xpath("//div[@ng-hide='searchText']"))
    .getAttribute("aria-hidden");
expect(previousEntry).toEqual('Masterson');

Your help is greatly appreciated.

like image 374
Dawn Avatar asked Jul 28 '26 18:07

Dawn


1 Answers

From what I understand it is the value attribute you need to check:

expect(element(by.id('requesterSearchInput')).getAttribute('value')).toEqual('Joe Smith');
like image 64
alecxe Avatar answered Jul 30 '26 07:07

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!