0

Pls consider the below code:

//CL.DCBS_List_AllElements = $$('#directClassBased > option')


this.shouldMatchDCBSList = async function () {
        var DCBSItems = await CL.DCBS_List_AllElements;
        console.log('Test Text = '+await CL.DCBS_List_AllElements.get(3).getText());
        console.log('Test Text 2 = '+await DCBSItems.get(4).getText());

When I execute this piece of code, the first console.log (console.log('Test Text = '+await CL.DCBS_List_AllElements.get(3).getText());) return the text as expected. But for the next one, when I am using it as a variable ( "await DCBSItems.get(4).getText()" ) , it gives me the following error:

Failed: DCBSItems.get is not a function

This is kind of strange as I could get the text returned before when I passed the elements using the parameters/variables. I spent many hours to fix it but its not working now. How can we fix it ?

1 Answer 1

1

If you await an ElementArrayFinder, you will get an array of ElementFinders. See https://github.com/angular/protractor/blob/master/lib/element.ts#L535

When calling ElementArrayFinder.get(index), Protractor will get the index in the ElementArrayFinder object. If you await an ElementArrayFinder, you will get an array. So in this case where you are using DCBSItems, instead of calling the .get you should call await DCBSItems[4].getText().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.