testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Selector not finding DOM element

Open eugengaspar opened this issue 8 years ago • 2 comments

I'm doing a simple test here, but I've seen a lot of people stumbled into this problem, but unfortunately I wasn't able to find a solution, so, therefore, I'm asking for your opinion.

Now, I have this string object, inside a link: <div class="price">12,45&nbsp;€</div>

I created this small test, to check the string value:

import { t, Selector } from 'testcafe';

fixture `OfferPage`.page `https://www.verivox.de/applications/broadband/#/offer?i=eyJmaWx0ZXIiOltudWxsLDE2MDAwLDEsbnVsbCwiMDIyMSIsMSwxLDEsbnVsbCwxLDEsbnVsbCwtMSxudWxsLG51bGwsInByaWNlLWFzYyIsMixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsbnVsbCxudWxsLG51bGwsNl0sImRpYWxvZyI6W251bGxdLCJvZmZlckNyaXRlcmlhIjpbIjYxMzQ0NyIsIjE4MjkyIixudWxsLCIyNCIsMywyLCI1MDAwMCIsIjEwMDAwIixudWxsLG51bGwsMSxudWxsLG51bGwsbnVsbCwiMiIsMSxudWxsLCIwMjIxIixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsMSw2LG51bGwsbnVsbCxudWxsXX0%3D`;
    test('1', async () => {
        const string = Selector('div.price');
        await t.expect(string.innerText).eql('12,45 €');
});

The error I get in terminal is this one: AssertionError: expected '12,45 €' to deeply equal '12,45 €'

I tried also other options, like the ones below, but with no luck unfortunatelly:

let price = Selector('div').withAttribute('class', 'price');
const result = price.parent('div.centered-content effective-price-wrapper');
console.log(result);
await t.expect(result.innerText).eql('12,45 €');

err: Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.

another try:

const string = await Selector('div.price')();
let pret = await Selector(string).innerText;
const rgx = /&nbsp;/gi;
await t.expect(pret.replace(rgx, '')).eql('12,45 €'.replace(rgx, ''));

err AssertionError: expected '12,45 €' to deeply equal '12,45 €'

I'm running put of ideas here :)

eugengaspar avatar Oct 19 '18 12:10 eugengaspar

It is a duplicate of the issue on StackOverflow. I've already answered there.

LavrovArtem avatar Oct 19 '18 14:10 LavrovArtem

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests. For TestCafe API, usage and configuration inquiries, we recommend asking them on StackOverflow.

lock[bot] avatar Mar 28 '19 03:03 lock[bot]