I recently started doing botting to try and get my hands on a better graphics card. My issue is this button: button html which has no name or anything useful that would allow my bot to detect it. I have tried using its XPath but to no success. my XPath attempt (I used the real XPath don't worry). Any help would be much appreciated :)
Asked
Active
Viewed 47 times
0
-
It's in a shadow root. You need to driver.execute() and return the .shadowroot of the element. – Arundeep Chohan Mar 24 '21 at 19:11
-
As mentioned I am very new. How exactly would I go about doing so? – winnermikkel3 Mar 24 '21 at 19:18
-
https://stackoverflow.com/questions/37384458/how-to-handle-elements-inside-shadow-dom-from-selenium – Arundeep Chohan Mar 24 '21 at 19:32
-
Thank you so much. I got it working :) – winnermikkel3 Mar 24 '21 at 20:21
2 Answers
0
driver.execute_script('return document.querySelector("core-button").shadowRoot.querySelector("a")').click()
use execute_script and then return the element inside the shadowRoot

PDHide
- 18,113
- 2
- 31
- 46
0
I used the following code to fix my issue.
browser = webdriver.Chrome()
def expand_shadow_element(element):
shadow_root = browser.execute_script('return arguments[0].shadowRoot', element)
return shadow_root
root1 = browser.find_element_by_tag_name('app-shell')
shadow_root1 = expand_shadow_element(root1)
root2 = shadow_root1.find_element_by_css_selector('request-page')
shadow_root2 = expand_shadow_element(root2)
root3 = shadow_root2.find_element_by_css_selector('box-content')
shadow_root3 = expand_shadow_element(root3)
pay_button = shadow_root3.find_element_by_css_selector("core-button")
pay_button.click()