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.

Source: Python Questions

LEAVE A COMMENT