Skip to content

finding elements sometimes cause error TypeError: object of type 'NoneType' has no len() or KeyError: 0 #65

@ombre42

Description

@ombre42

Sometimes the underlying call to Selenium methods such as find_elements_by_xpath return a dict with value=None. This None value is propagated all the way up to _element._element_find, where len() is used to see how many elements were found. This will cause Wait Until Page Contains Element to fail immediately, since you can't use len on None.
Unfortunately I don't have a simple test/page to reproduce, but here's a log from executing Selenium2Library.Wait Until Page Contains Element id=delivery_date_select, 1m

08:31:43.590 DEBUG POST http://127.0.0.1:50341/session/a61ed99c-c9ed-4e49-9045-8b3c7724eeac/elements {"using": "id", "sessionId": "a61ed99c-c9ed-4e49-9045-8b3c7724eeac", "value": "delivery_date_select"}
08:31:44.160 DEBUG POST http://127.0.0.1:50341/session/a61ed99c-c9ed-4e49-9045-8b3c7724eeac/elements {"using": "id", "sessionId": "a61ed99c-c9ed-4e49-9045-8b3c7724eeac", "value": "delivery_date_select"}
08:31:44.573 FAIL TypeError: object of type 'NoneType' has no len()
08:31:44.574 DEBUG Traceback (most recent call last):
File "", line 2, in wait_until_page_contains_element
File "C:\apps\Python27\lib\site-packages\Selenium2Library\keywords\keywordgroup.py", line 12, in _run_on_failure_decorator
return method(_args, *_kwargs)
File "C:\apps\Python27\lib\site-packages\Selenium2Library\keywords_waiting.py", line 63, in wait_until_page_contains_element
self._wait_until(timeout, error, self._is_element_present, locator)
File "C:\apps\Python27\lib\site-packages\Selenium2Library\keywords_waiting.py", line 71, in _wait_until
while not function(*args):
File "C:\apps\Python27\lib\site-packages\Selenium2Library\keywords_element.py", line 593, in _is_element_present
return (self._element_find(locator, True, False, tag=tag) != None)
File "C:\apps\Python27\lib\site-packages\Selenium2Library\keywords_element.py", line 515, in _element_find
if len(elements) == 0: return None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions