pythonhtmlseleniumselenium-webdriverwebbot

How to read span through aria-hidden?


I've been trying for about 2 hours now with no luck to see how to read text between a span that has an "aria-hidden=true" tag. The code for the site is like this:

<div class="badge">
    <span aria-hidden="true">123</span>
</div>

Any idea how you can view the text with xpath or anything similar? My current code is this, but returns random span text from across the page for some reason.

for i in web.find_elements(xpath="//div[contains(concat(' ', @class, ' '), ' badge ')]//span[1]"):
                    print(i.get_attribute("innerText"))

Any help would be greatly appreciated


Solution

  • Based on the HTML you posted, I don't see the attribute innerText in the span element. To get the text of the element in Selenium, you should use getText()

    for i in web.find_elements(xpath="//div[contains(concat(' ', @class, ' '), ' badge ')]//span[1]"):
                        print(i.getText())