I'm using Python 3.11.5, and I want to extract text from a Webelement with selenium.

I use Chromedriver as a driver, and I want to find an element By.CLASS_NAME

Here is my code

enter image description here

What happens ?

  • When I print (element), it gives me a Webdriver element, which I can't read.

  • When I print (element.text), it gives me an error :

Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001DDFE4F0690>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée')': /session/0109eeaf781d2f899ee82e0fd10eac19/execute/sync

What have I tried ?

  • After using driver.get(url), I already tried to apply time.sleep(10)

  • I checked my versions of Chrome + Chromedriver

  • I disabled my proxy

Do you have any idea about what the problem is ?

  • 1
    Have you tried moving print element.text to before the driver.quit statement? The error message suggests that a connection via the driver is necessary to read the element properties.
    – Kate Paulk
    Commented Mar 12 at 12:13
  • @KatePaulk I'm gonna try this. Data comes in and out at random timings on the website I'm scraping so I can't tell you when I'll know, but I'll let you know. Thanks for the advice !
    – Rodgoupil
    Commented Mar 12 at 23:53

1 Answer 1


If you've successfully located the element but are encountering issues when trying to access its text, the issue could be one of several things:

The element does not contain text: It might be that the element you've located doesn't actually contain text. This could be because the text is within a child element, or because the element is used for layout rather than content.

Stale element reference: If the page updates dynamically after you've located the element, you might have a reference to an element that is no longer attached to the page's DOM.

If this doesn't resolve the issue, please ensure that the element is fully loaded when you try to access its text, and that you're accessing the correct part of the element hierarchy. If there's an iframe involved or the text is within a shadow DOM, additional steps are needed to access the content.

I recommend opening a the developer console and selecting the elements tab. Then searching for the selector ensuring the text you’d like to access is within the element you’re searching for.

I also recommend where possible using the ID selector over class name as it’s normally faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.