Interact with the shadow DOM in Selenium

See here for the original answer.

What I noticed when using the Selenium head to manually debug is that the cookie element does not show up on my machine. If you have anything on your browser/machine that could be preventing the cookie popup, that may be a factor.

An additional problem is that the tiktok-cookie-banner element uses the shadow DOM, which introduces a whole separate element of complexity. To solve this problem, I recommend the shadow-automation-selenium package, which the documentation explains how to use to interact with the element you are interested in. More information about the shadow DOM can be found in this thread.


Tags

  1. python (Private)
  2. selenium (Private)
  3. stack-overflow (Private)
  4. answer (Private)