I don’t know how to read the text inside the label: "Industry Avg 1.1x".
This is the website: https://simplywall.st/stocks/us/energy/nyse-hal/halliburton#valuation
<text fill="#1B222D" font-size="13" transform="translate(-111 0)">Industry Avg 1.1x</text>
I really don’t know how to address to that element in order to get the text.
Image of the graph with the label with the needed information:
I hope somebody can help.
Thanks a lot,
That label doesn’t appear until you’ve scrolled it into view. I think the easiest way is to scroll all the way to the bottom, at which point the element can be found. It’s tricky though because you have to scroll "like a user would". To do that, I believe the following should work, although it is far from optimized:
last_height = driver.execute_script("return document.body.scrollHeight") while True: driver.execute_script("window.scrollTo(0, document.body.scrollHeight-1000);") # Wait to load the page. driver.implicitly_wait(3) # seconds new_height = driver.execute_script("return document.body.scrollHeight") if new_height == last_height: break last_height = new_height driver.implicitly_wait(3) # seconds
Probably scratch the above. I found you can identify the section surrounding the element and click it to make your element appear. Try this:
Then, to identify the element and get the text, try the following:
text_you_want = driver.find_elements_by_css_selector('g > text[font-size="13"]').innerHTML
Answered By – C. Peck