I have been trying to scrape data from the following site using Selenium & Python: https://developer.salesforce.com/docs/atlas.en-us.netzero_cloud_dev_guide.meta/netzero_cloud_dev_guide/sforce_api_objects_airtravelemssnfctr.htm#maincontent.
I want to obtain the Fields table but nothing seems to be working. Anytime I try to get any element from the site I get the following error:
NoSuchElementException: Message: no such element: Unable to locate element
It has since been pointed out to me that the reason this is occurring is because the element I want to access is inside 2 #shadow-root (open)
. I am having trouble figuring out how to access this.
I am referencing this article: How to handle elements inside Shadow DOM from Selenium. However, I am having a hard time altering the code for my needs.
Does anyone know how I can access the element I need behind the Shadow DOM? Desperately need help with this as I cannot figure it out.
Attempting to use the code below but I can't figure out which elements I should be referencing in each root variable in the find_element_by_id function. If anyone has advice on how
driver = webdriver.Chrome()
def expand_shadow_element(element):
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
return shadow_root
driver.get("chrome://settings")
root1 = driver.find_element_by_tag_name('settings-ui')
shadow_root1 = expand_shadow_element(root1)
root2 = shadow_root1.find_element_by_css_selector('[page-name="Settings"]')
shadow_root2 = expand_shadow_element(root2)
root3 = shadow_root2.find_element_by_id('search')
shadow_root3 = expand_shadow_element(root3)
search_button = shadow_root3.find_element_by_id("searchTerm")
search_button.click()
text_area = shadow_root3.find_element_by_id('searchInput')
text_area.send_keys("content settings")
root0 = shadow_root1.find_element_by_id('main')
shadow_root0_s = expand_shadow_element(root0)
root1_p = shadow_root0_s.find_element_by_css_selector('settings-basic-page')
shadow_root1_p = expand_shadow_element(root1_p)
root1_s = shadow_root1_p.find_element_by_css_selector('settings-privacy-page')
shadow_root1_s = expand_shadow_element(root1_s)
content_settings_div = shadow_root1_s.find_element_by_css_selector('#site-settings-subpage-trigger')
content_settings = content_settings_div.find_element_by_css_selector("button")
content_settings.click()