How do I automate a button click, found under a shadow root, using Selenium in Python?

30 Views Asked by At

I want to automate the clicking of a certain button in a popup window, using Python.

The button I am trying to click is the "Cancel" button in the picture below: (https://i.stack.imgur.com/mt8O6.png)

The source code for the "Cancel" button is: (https://i.stack.imgur.com/G2Vom.png)

It's under a shadow root, and I don't know how to find the path to these kinds of buttons using Python.

How can I write a code to get this button to click?

The code I've tried so far is this, and it doesn't work:

host1 = driver.find_element(By.TAG_NAME, 'print-preview-app')
root1 = getShadowRoot(host1)

host2 = root1.find_element(By.TAG_NAME, 'print-preview-sidebar')
root2 = getShadowRoot(host2)

host3 = root2.find_element(By.TAG_NAME, 'print-preview-button-strip')
root3 = getShadowRoot(host3)

cancel_button = root3.find_element(By.TAG_NAME, 'cr-button')
cancel_button.click()

Thank you!

0

There are 0 best solutions below