4

I have a problem with getting a text from elements on a web page. I'm using TestCafe e2e framework and want to print the contents of a text web element to console. Can you provide some code?

const getInnerText = ClientFunction(() => homePage.kzLink.innerText);
console.log(getInnerText());

what i get:

ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Lev Boichenko
  • 497
  • 1
  • 5
  • 9

1 Answers1

5

To execute a client function, call it with the await keyword and a dependency.

const getInnerText = ClientFunction(() => homePage.kzLink.innerText, { 
    dependencies: { homePage.kzLink }
});

test('My Test', async t => {
    const text = await getInnerText();
    console.log(text);
});
Stiks
  • 221
  • 1
  • 9
  • 2
    And if you add dependency: const getInnerText = ClientFunction(() => homePage.kzLink.innerText, { dependencies: { homePage.kzLink } }); – Stiks Jan 29 '19 at 08:26
  • If `homePage.kzLink` is a Selector, you could simply do: `console.log(await homePage.kzLink.textContent)` – hdorgeval Jan 29 '19 at 20:17