Seeking Expert Help with Selenium WebDriver and C# for Shadow DOM Interaction

12/27/2023 18:12 Givemoney#1
Hello,

I am currently working on a web automation task involving Selenium WebDriver and C#, and I'm encountering difficulties with interacting with shadow DOM elements, specifically for accepting cookies on one website. The challenge lies in clicking the 'Accept All' button within the cookie consent banner, which is nested inside a shadow DOM.

Here's a brief overview of the issue and what I've tried:

Problem:
  1. I need to automate clicking the 'Accept All' button on the cookie consent banner of "a website"
  2. The button is hidden within a shadow DOM, making it challenging to interact with using standard Selenium WebDriver methods.
Current Approach:
  1. Using Selenium WebDriver with C# for automation.
  2. Employing WebDriverWait to ensure the element is present and IJavaScriptExecutor to navigate the shadow-root to the specific button.
  3. The code snippet I've been working with involves locating the shadow host and then attempting to find and click the accept button within it.

Code Snippet:


Expected Outcome:
  1. I anticipated that the script would navigate through the shadow DOM and locate the 'Accept All' button, allowing the automation to proceed by accepting cookies.


Assistance Requested:
  1. Insights or corrections to the current approach to effectively click the 'Accept All' button within the shadow DOM.
  2. Any advice or alternative strategies for handling shadow DOM elements more effectively in Selenium with C#.
  3. I am open to any suggestions and would greatly appreciate any help offered. I'm willing to provide compensation for expert advice and solutions that successfully resolve this issue.

Thank you in advance for your time and assistance!