john-doherty / selenium-cucumber-js

Browser automation framework written in pure JavaScript using official selenium-webdriver and cucumber-js
ISC License
120 stars 89 forks source link

Helper getElementsContainingText trim #50

Closed ghost closed 6 years ago

ghost commented 6 years ago

What about removing whitespaces from both sides of strings in the condition of 'getElementsContainingText' helper ?

By changing it with something like this:

if (elements[i][txtProp].trim() === content.trim()) {
    results.push(elements[i]);
}

The problem I encounter is that HTML tags had not the same innerText and textContent string values and both could contained (not the same) leading and trailing whitespace(s) and carriage return(s).

So, If I want to search "Hello" in these examples, currently only the first will work all the time:

<span>Hello</span>

<span> Hello  </span>

<span>
    Hello
</span>

As a workaround, I copy-paste the getElementsContainingText content function in my test code with the fix above.

john-doherty commented 6 years ago

Hi @afuca, good point. Perhaps you could make the change and submit a pull request?

ghost commented 6 years ago

Fixed with release 1.5.9. Thank you.