2021年4月11日星期日

Selenium is returning empty text for elements that definitely have text

I'm practicing trying to scrape my university's course catalog. I have a few lines in Python that open the url in Chrome and clicks the search button to bring up the course catalog. When I go to extract the texting using find_elements_by_xpath(), it returns blank. When I use the dev tools on Chrome, there definitely is text there.

from selenium import webdriver  import time    driver = webdriver.Chrome()  url = 'https://courses.osu.edu/psp/csosuct/EMPLOYEE/PUB/c/COMMUNITY_ACCESS.OSR_CAT_SRCH.GBL?'  driver.get(url)  time.sleep(3)    iframe = driver.find_element_by_id('ptifrmtgtframe')  driver.switch_to.frame(iframe)  element = driver.find_element_by_xpath('//*[@id="OSR_CAT_SRCH_WK_BUTTON1"]')  element.click()  course = driver.find_elements_by_xpath('//*[@id="OSR_CAT_SRCH_OSR_CRSE_HEADER$0"]')  print(course)  

I'm trying to extract the text from the element 'OSU_CAT_SRCH_OSR_CRSE_HEADER'. I don't understand why it's not returning the text values especially when I can see that it contains text with dev tools.

https://stackoverflow.com/questions/67052519/selenium-is-returning-empty-text-for-elements-that-definitely-have-text April 12, 2021 at 12:01PM

没有评论:

发表评论