protractor
protractor copied to clipboard
Cannot read property 'indexOf' of null error :Expected condition textToBePresentInElementValue
If user tries to access an element that does not have the attribute 'value' then the EC.textToBePresentInElementValue throws Cannot read property 'indexOf' of null error :
let EC = protractor.ExpectedConditions;
describe('Test', function () {
it('test {Regression} {Sanity} {Sanity}', async function () {
await browser.get("http://juliemr.github.io/protractor-demo/")
let resultElement=element(by.xpath('//h2'))
await browser.wait(EC.textToBePresentInElementValue(resultElement, 'Z'), 5000,"this is first 1");
});
});
Expected:
Script should wait till value attribute is present and contains in the text. If not, it should time out with customised message "this is first 1",
Protractor version: Version 5.4.2 Node: v10.16.3
Maybe a good solution would be to use by.cssContainingText("h2", "Z") and then use .presenceOf. This will basically do the same thing as what you have done as you will be looking for an element with the h2 tag in it and "Z" to be contained inside of it. Even if the h2 element loads, it will not prompt the test to continue until the text is populated inside of the element.
Maybe a good solution would be to use by.cssContainingText("h2", "Z") and then use .presenceOf. This will basically do the same thing as what you have done as you will be looking for an element with the h2 tag in it and "Z" to be contained inside of it. Even if the h2 element loads, it will not prompt the test to continue until the text is populated inside of the element.
Hi @Fuun347 textToBePresentInElementValue checks for the attribute "value" and not the text
Haven't used that one before so I just assumed it was checking for element to contain text inside of it. What you can do, but is not very ideal is getAttribute("value") and use expect to compare if it matches, but that won't work very well if it takes longer for the value to appear inside of the element.
Haven't used that one before so I just assumed it was checking for element to contain text inside of it. What you can do, but is not very ideal is getAttribute("value") and use expect to compare if it matches, but that won't work very well if it takes longer for the value to appear inside of the element.
Thanks @Fuun347 i already wrote a promise that will check the status=getAttribute('value')==='' and returns !status , so that the wait waits till getAttribute('value') is not null. : ) The bug was raised to help others who encounter such a issue.
hi the bug is that textToBePresentInElementValue use getAttribute that could return null and doing actualText.indexOf(text) > -1 where actualText is the return of getAttribute without checking is null or not
it 's not fixed on 7.0
https://github.com/angular/protractor/blob/release-7.0/lib/expectedConditions.ts#L240
but seems catch on master branch but i think the code will not wait for a non null value in element value and directly raise
https://github.com/angular/protractor/blob/master/lib/expectedConditions.ts#L237
@praveendvd Could you share your solution, pls?