Python Selenium: Finds H1 Element But Returns Empty Text String
I am trying to get the text in the header on this page: iShares FTSE MIB UCITS ETF EUR (Dist) The tag looks like this:
)))
text
property allow you to get text from only visible elements while textContent
attribute also allow to get text of hidden one
Try to replace
new_name = driver.find_element_by_xpath(xp_name).text
with
new_name = driver.find_element_by_xpath(xp_name).get_attribute('textContent')
or simply handle the second (visible) header:
driver.find_elements_by_xpath('//h1[@class="product-title "]')[1].text
Solution 2:
As @ahmad-moussa mentioned, for me to the solution was:
import time
(...)
time.sleep(1)
# before
<webelement>.text
Post a Comment for "Python Selenium: Finds H1 Element But Returns Empty Text String"