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

[page.click] Node is either not visible or not an HTMLElement #1990

Closed
JonnyLeiZhang opened this issue Apr 27, 2020 · 11 comments
Closed

[page.click] Node is either not visible or not an HTMLElement #1990

JonnyLeiZhang opened this issue Apr 27, 2020 · 11 comments

Comments

@JonnyLeiZhang
Copy link

Context:

Playwright Version: 0.15.0
Operating System: Ubuntu 18.04.4

Code Snippet

(async () => {
  // below lines used to create a profile with name 'add_profile_test'
  await page.click('#add-profile-btn');
  await page.fill('#profile input[type=text]','add_profile_test');
  await page.click('#dialog-btn');
  // after create it, then select it
  await page.waitForSelector('text=add_profile_test', {waitFor: 'visible',});
  await page.click('text=add_profile_test');
})

Describe the bug

when try to click the element ('text=add_profile_test'), it reports 'Node is either not visible or not an HTMLElement'.
but if I add one line page.waitFor(1000) before await page.click('text=add_profile_test'), then it can work, I don't understand why. Shouldn't waitForSelector and waitFor function work for this?

@thernstig
Copy link
Contributor

The waitForSelector should not be needed at all since actions like page.click() automatically auto-wait for elements. Check this: https://github.com/microsoft/playwright/blob/master/docs/core-concepts.md#auto-waiting

But, if it is visible when doing the page.click() the above is indeed strange.

(Hi Lei 😄)

@pavelfeldman
Copy link
Member

Looks like a bug. Does await page.click('#dialog-btn'); do async api call followed by a dom update or page navigation?

@thernstig
Copy link
Contributor

I also experienced this now. But it is intermittent. This is my code that fails on this:

  await page.click('#menu-toggle');
  await page.click('tree-item >> text=App Name');

#menu-toggle opens up a left-side menu. The menu slides in as an animation. Note that all selectors here is in an open shadow DOM. It seems both our cases are however failing on the text selector. The text is also in the shadow DOM.

@dgozman
Copy link
Contributor

dgozman commented Apr 27, 2020

Could anyone share a complete repro script please? Otherwise, we can keep guessing what the issue is 😄

@JonnyLeiZhang
Copy link
Author

Hi Guys, after I change
await page.click('text=add_profile_test'); to
await page.click('text="add_profile_test"'); then it can work.
but the error information still confuse easily, why it doesn't directly return timeout.(since no element contains string 'text=add_profile_test' )

@JonnyLeiZhang
Copy link
Author

I also experienced this now. But it is intermittent. This is my code that fails on this:

  await page.click('#menu-toggle');
  await page.click('tree-item >> text=App Name');

#menu-toggle opens up a left-side menu. The menu slides in as an animation. Note that all selectors here is in an open shadow DOM. It seems both our cases are however failing on the text selector. The text is also in the shadow DOM.

have a try
await page.click('tree-item >> text=App Name'); =>
await page.click('tree-item >> text="App Name"');

@dgozman
Copy link
Contributor

dgozman commented Apr 28, 2020

Hi Guys, after I change
await page.click('text=add_profile_test'); to
await page.click('text="add_profile_test"'); then it can work.
but the error information still confuse easily, why it doesn't directly return timeout.(since no element contains string 'text=add_profile_test' )

Very interesting! The difference between text=add_profile_test and text="add_profile_test" is that latter is a strict match, while the former may find an element that has add_profile_test as a substring. Could it be there are two elements that contain add_profile_test, but one of them also has something else?

@JonnyLeiZhang
Copy link
Author

Hi Guys, after I change
await page.click('text=add_profile_test'); to
await page.click('text="add_profile_test"'); then it can work.
but the error information still confuse easily, why it doesn't directly return timeout.(since no element contains string 'text=add_profile_test' )

Very interesting! The difference between text=add_profile_test and text="add_profile_test" is that latter is a strict match, while the former may find an element that has add_profile_test as a substring. Could it be there are two elements that contain add_profile_test, but one of them also has something else?

I have checked it's unique string in the whole page source.
and add
await page.waitFor(3000); before
await page.click('text=add_remove_profile_test');

then it can work the same with await page.click('text="add_remove_profile_test"');
so I think this can also prove that the string is unique.

@thernstig
Copy link
Contributor

I have a hard time sharing a repro of my code, since it is a private project with a lot of code in it. I´ve always used text=App Name in my case, meaning I do the case-insensitive, substring matching.

Wild guess: Does it have something to do with that the menu in my case is animating with the combination of the css shadow dom selector and then the text in the shadow dom, and that the text contains spaces. (Ok I just realized that "guess" did not help at all).

@thernstig
Copy link
Contributor

@dgozman @pavelfeldman I believe this has been fixed in 0.16.0. Is it possible that #2047 fixed this?

I've tested the test case we have multiple times now and never gotten the failure again, whilst I got it frequently before 0.16.0.

@dgozman
Copy link
Contributor

dgozman commented May 4, 2020

@dgozman @pavelfeldman I believe this has been fixed in 0.16.0. Is it possible that #2047 fixed this?

That's wonderful! It might be #2047 or #2020 or any other improvement 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants