0

I have a website, let's say "exampleA.com"

There are 12 clickable boxes on it, and clicking each box will take me to a different page. For example, clicking box1 will take me to page1.com, clicking box2 will take me to page2.com. I want to click every box on this page.

I am currently facing an issue where I get the following error

playwright._impl._api_types.Error: Element is not attached to the DOM.
attempting click action: waiting for element to be visible, enabled and stable

while running the following code:

boxes = page.query_selector_all(".something")
box1.click()
page.go_back()
box2.click()
page.go_back()

I have tried adding the following in between the code:

page.wait_for_load_state("networkidle")
page.wait_for_timeout(5000)

But the error still persists. How can I fix this bug?

ggorlen
  • 44,755
  • 7
  • 76
  • 106
akuan10
  • 111
  • 6
  • 2
    The question is rather pseudocodey, so I can't verify that a solution works on your page, but either loop over the elements and click each one, or pick out the ones you want specifically and click them. What's `box1`? Shouldn't that be `boxes[0].click()`? Can you share a [mcve]? – ggorlen May 01 '23 at 13:57
  • 2
    Yes , this is not enough. Please share the minimal reproducible example and possibly stack trace to relate it with precise line number of the error. – Vishal Aggarwal May 01 '23 at 14:13
  • Does this answer your question? [Playwright "Element is not attached to the DOM"](https://stackoverflow.com/questions/69422216/playwright-element-is-not-attached-to-the-dom) – Code-Apprentice May 01 '23 at 21:33

1 Answers1

0

Let try this:

page.locator(".something").first.wait_for(state="attached", timeout=5000)

Playwright: https://playwright.dev/python/docs/api/class-locator#locator-wait-for