[Python] Python selenium shadow root closed

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    i'm testing a webscrapping and click scenario in this website: 'https://www.kto.com/pt/esportes/?page=live')

    driver.get('https://www.kto.com/pt/esportes/?page=live')

    I want to click in 'Basquete' button inside live section, but this button is inside a shadow-root(closed).

    I try to use attachshadow to change mode to open using this code below:

    driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': """ Element.prototype._attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function () { return this._attachShadow( { mode: "open" } ); }; """})



    After that, i tried to use a xpath find element using de xpath of this button:


    driver.find_element(By.XPATH, '//*[@id="sports-container"]/div//div[1]/div[2]/main/div/div/div[1]/div[1]/div/div[2]/button').click()



    But i received the error message:

    NoSuchElementException

    (No symbol) [0x00007FF6D21
    (No symbol) [0x00007FF6D215BD04]
    BaseThreadInitThunk [0x00007FFF4A30257D+29]
    RtlUserThreadStartr [0x00007FFF4B2CAA58+40]
    Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...



    It seems the attackshadow is not working and i'm not getting access do shadow-root nodes

    I'm new in selenium and i got this problem. Is it possible resolve this problem ?

    Continue reading...

Compartilhe esta Página