Home > Net >  Best way to click a button within #shadow-root (open) via Python and Selenium
Best way to click a button within #shadow-root (open) via Python and Selenium

Time:08-14

I am currently dabbling in Python in combination with Selenium. Here I came across the topic of Java Script buttons. I am looking for the smartest way to find out how to execute a Java-Script code (in this case a button) the easiest way.

My goals:

  1. Open web page enter image description here

    CodePudding user response:

    The element Jetzt berechnen is within #shadow-root (open) and is an <input> element.

    Jetzt


    Solution

    To click on Jetzt berechnen you can use the following line of code:

    berechnen_button = browser.execute_script("""return document.querySelector('kredit-rechner').shadowRoot.querySelector('input.calculator__submit-button')""")
    berechnen_button.click()
    
  • Related