Exception triggered in EventFiringWebDriver when debugging in PyCharm

Debugging Selenium script with EventFiringWebDriver in PyCharm, cause exception to be logged:

 'WebDriver' object has no attribute '__len__'

It slows down IDE but do not break (stop) the script.

Here is full code:

from selenium import webdriver
from selenium.webdriver.support.event_firing_webdriver import EventFiringWebDriver
from selenium.webdriver.support.events import AbstractEventListener


class ScreenshotListener(AbstractEventListener):
    def on_exception(self, exception, driver):
        print(exception)


driver = webdriver.Chrome('chromedriver.exe')
ef_driver = EventFiringWebDriver(driver, ScreenshotListener())
ef_driver.get('https://google.com/')
title = ef_driver.title
driver.quit()

assert "Google", title

When I run attached script in standard mode everything is OK.

But running with PyCharm Debug (here is output from beginning of Debug console):

C:Proselenium-debugvenvScriptspython.exe "C:Program FilesJetBrainsPyCharm Community Edition 2020.1.1pluginspython-cehelperspydevpydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 59668 --file C:/Pro/selenium-debug/simple_test.py

I get those exceptions (every time when I call ef_driver):

'WebDriver' object has no attribute '__len__'
'WebDriver' object has no attribute '__len__'

It not stopping the script, it just cause debugger to be slow (it updates driver and focus is set to the browser).

Any idea why it is triggered and logged?

Bonus: Running debugging in console with pdb is OK, so this looks like strictly PyCharm Debug connected thing

Answer

Looks like PyCharm debug checks if an object has a __len__ attribute:

elif hasattr(v, "__len__")

and the object WebDriver has no __len__.

A solution could be (from the link below) to warp with trycatch:

try:
    if is_numeric_container(type_qualifier, typeName, v):
        xml_shape = ' shape="%s"' % make_valid_xml_value(str(v.shape))
    elif hasattr(v, "__len__") and not is_string(v):
        try:
            xml_shape = ' shape="%s"' % make_valid_xml_value("%s" % str(len(v)))
        except:
            pass
except KeyError:
    pass

Please check this track: https://youtrack.jetbrains.com/issue/PY-39954