[Python] How to get the path to webelement from shadow DOM for further use in...

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I feel difficulties to extract the locator for "Accept all" button from usercentrics dialog, the DOM is the following: DOM and UI

    I am using the following:

    def user_centrics_accept(driver):
    # Execute JavaScript to get the shadow root
    shadow_root_script = "return document.querySelector('#usercentrics-cmp-ui').shadowRoot"
    shadow_root = driver.execute_script(shadow_root_script)

    # Find an element within the shadow root using CSS Selector
    element_in_shadow_dom = shadow_root.find_element(By.CSS_SELECTOR, 'locators_path')
    element_in_shadow_dom.click()


    So can anybody tell how to get a clear path to 'accept' button ('locators_path'), just to click it?

    Continue reading...

Compartilhe esta Página