Hi can't find or access elements inside a shadow root. How can I check if Im in the correct shadow-root or fix the code?
def getShadowRoot(host):
shadowRoot = driver.execute_script("return arguments[0].shadowRoot", host)
return shadowRoot
#enter into shadow root.
shadow = driver.find_element(By.CLASS_NAME, 'proceeds-breakdown-container')
root2 = getShadowRoot(shadow)
#tried to get via list and first element both give empty list or error
posdata = root2.find_elements(By.CLASS_NAME,'second-level-breakdown-amount positive-amount')
if posdata:
print("printing elements")
for element in posdata:
print(element.text)
else:
#list is always empty
print("The list is empty.")
#error can't find element
revenue = root2.find_element(By.CLASS_NAME,'second-level-breakdown-amount positive-amount').text
Expecting: Find the element inside the shadow-root
Trying: access several elements via class, xpath, but not working.
You can't directly access The Element of Shadow Root For example try this
driver.execute_script()
Execute Javascript and then Work with that element! You can also try to detect the element via inspect element>console to make sure the syntax is okay!Example Code block: