Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if an element exists resolves immediately without waiting for timeout #8186

Closed
nermin99 opened this issue May 8, 2024 · 3 comments
Labels
TYPE: bug The described behavior is considered as wrong (bug).

Comments

@nermin99
Copy link

nermin99 commented May 8, 2024

What is your Scenario?

I have a user flow where, depending on the input, a new element might appear, and if so I need to click on the element in order to continue. So I tried awaiting $element.exists in an if, but it just returns/resolves immediately without waiting for the page to render.

I'd like a way to wait for an element that might appear.

What is the Current behavior?

if (await $element.exists) // resolves immediately

What is the Expected behavior?

if (await $element.exists) // resolves with built-in wait mechanism https://testcafe.io/documentation/402827/guides/advanced-guides/built-in-wait-mechanisms

What is the public URL of the test page? (attach your complete example)

https://google.com

What is your TestCafe test code?

await t.click($buttonThatLoadsPageWithNewConditionalContent)

let textThatMaybeExists = ''
if (await $element.exists) {
    textThatMaybeExists = await $element.textContent
    // ...
}

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

TestCafe version

3.6.0

Node.js version

21.7.1

Command-line arguments

testcafe chrome

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

@nermin99 nermin99 added the TYPE: bug The described behavior is considered as wrong (bug). label May 8, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 8, 2024
@PavelMor25
Copy link
Collaborator

Hello @nermin99,

Please try the solution from this thread and let us know your results

@PavelMor25 PavelMor25 added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need response An issue that requires a response or attention from the team. labels May 14, 2024
@nermin99
Copy link
Author

Thanks @PavelMor25

Replacing await $element.exists with await $element.visible worked as expected.

But how come .visible isn't in your documentation?
https://testcafe.io/documentation/402666/reference/test-api/selector

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 15, 2024
@github-actions github-actions bot removed the STATE: Need clarification An issue lacks information for further research. label May 15, 2024
@PavelMor25
Copy link
Collaborator

Hello,

This property belongs to element-based DOMNodeState objects, not to the Selector object itself.

Thank you for your report.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

2 participants