waitForText is not working to locate text but waitUntil works

Viewed 44

I am getting ready to pull my hair out. Not sure what I am doing wrong but here is the issue:

I have a textbox for which I am verifying an error message for. The html looks something like this:

<span class="text-field-error" data-valmsg-for="Name" data-valmsg-replace="true"><span id="Name-error" class="">There are invalid characters being used.</span></span>

My xpath to locate the error message looks something like this:

//span[@id='Name-error']

I am using the following command to verify the error message:

driver.waitForText('//span[@id='Name-error']','There are invalid characters being used.')

This verification fails.

However, when I try the following command, it works fine.

driver.waitUntil('//span[@id='Name-error']',"_.innerText.includes('There are invalid characters being used.')")

I have verified there is no hidden whitespace in the first instance. I have to use waitForText vs waitUntil to keep up with coding standards within my project.

Please advise, Peter.

1 Answers

I have no idea, maybe it is a bug. If you can provide a way to replicate, that will help the community: https://github.com/karatelabs/karate/tree/develop/examples/ui-test

Meanwhile see if this works:

waitForText('body', 'There are invalid characters being used')

I can't help noticing that you are not using double-quotes when needed.

waitForText("//span[@id='Name-error']", 'There are invalid characters being used')
Related