r/SeleniumPython • u/Lucian_the_lost • Sep 24 '24
Help Unable to access "#text" element?
Hello, I'm new to web scraping and selenium and wanted to web scrape this website:
https://rarediseases.info.nih.gov/diseases/21052/10q223q233-microduplication-syndrome
one of the texts I want to grab is the disease summary, which seems to be the child of the element denoted by this XPATH: "/html/body/app-root/app-disease-about/disease-at-a-glance/div/div/div[2]/div[1]/app-disease-at-a-glance-summary/div/div[1]/div/div"

the line of code I'm trying to run to grab it is:
driver.find_element(By.XPATH, "/html/body/app-root/app-disease-about/disease-at-a-glance/div/div/div[2]/div[1]/app-disease-at-a-glance-summary/div/div[1]/div/div").textHowever, whenever my code runs, it returns an empty ' ' string
I've tried adding "//*" at the end of the XPATH as it seems like the text is actually stored as a child element, but I get a "no such element" exception. I've looked into CSS selectors but seem to run into the same issues. I've looked everywhere and couldn't find a solution or explanation, but I also recognize my experience with HTML and web scraping is limited. Any suggestions and help are greatly appreciated!
1
u/mevist77 Sep 25 '24
Try finding element by CSS_SELECTOR: app-disease-at-a-glance-summary .summary-wrapper .fs-md-18
Worked for me
1
u/Soga_Toffolo 2d ago
`#text` in the inspector isn't an actual HTML tag you can target with `//*`, its just how the browser represents the raw string node inside the div. If the parent div is returning empty, the element might not be visible in the viewport yet, so `.get_attribute("textContent")` should bypass that
1
u/Original-Program-279 Sep 24 '24
try the wait element method