question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Add isAttached or isExisting to element

See original GitHub issue

Summary

Implement an easy way to check whether an element is attached to the DOM.

test('test', async ({ page }) => {
  const isExisting = await page.locator('body').isExisting() // returns true or false
})

It’s really not convenient to do something like this every time

const els = await page.locator('body').elementHandles()
const isExisting = els.length > 0

Existing functionality

Please don’t suggest waiters (wait for state to be attached/not attached, etc), visibility checks (isVisible, isHidden) or similar. This is completely different requests. Thank you

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
purepearcommented, Jun 7, 2022

I was also looking for a simple way to assert element presence

I guess we could do:

await expect(page.locator('.item').first()).toHaveCount(1) // to exist
await expect(page.locator('.item')).toHaveCount(0) // not to exist

but it seems like a very common assertion so maybe having toExist()/toBeInTheDocument()/toBePresent() is worth it:

await expect(page.locator('.item')).toExist()
await expect(page.locator('.item')).not.toExist()

BTW @grybykm locator.waitFor() might be helpful in your case:

await page.locator('.item').waitFor({ state: 'attached' })
3reactions
grybykmcommented, Apr 12, 2022

It would be also nice to have an assertion for this. Something like this:

await expect(page.locator('body')).toExist()
await expect(page.locator('body')).not.toBeAttached()
Read more comments on GitHub >

github_iconTop Results From Across the Web

isExisting - WebdriverIO
Returns true if element exists in the DOM. ... As opposed to other element commands WebdriverIO will not wait for the element to...
Read more >
How to check whether dynamically attached event listener ...
Step 1: First, you will need a function that can traverse the storage object and return the record of an element given the...
Read more >
How To Use Deep Selectors In Selenium WebdriverIO
This blog deep-dives into learning deep selectors in Selenium WebdriverIO and how to use them while writing tests for Selenium automation ...
Read more >
Everett's harborfront public access capital improvement plan
New maritime planning concepts and individual public access features were ... the element is existing, will be improved or is a proposed new...
Read more >
Learn Webdriver IO - STARTER EDITION - Part 1
There are a variety of ways we can tell WebdriverIO what element we want. ... Services are used to add extra functionality our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found