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!