8

Based on various forum discussions, the TestCafe documentation, and trying it out to compare results, I am still not certain which is the correct (or best) way to assert that a page element is visible.

await t.expect(Selector('#elementId').visible).ok();

vs

await t.expect(await Selector('#elementId').visible).ok();

Or are these both incorrect and there is another way that is preferable? How does this compare to asserting that an element exists? Or other properties of the element, such as :checked?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Meg
  • 938
  • 9
  • 20

2 Answers2

8

Actually, both variants are possible. Nevertheless, it is better to use the first one because the second variant may raise errors at the stage of obtaining the Element State:

Smart Assertion Query Mechanism

Or other properties of the element, such as :checked

You can obtain the Element State and use its checked option.

Marion
  • 1,074
  • 5
  • 10
1
await t.expect(Selector('#elementId').visible).eql(true);

This should help

Ganesh H
  • 1,649
  • 3
  • 14
  • 20