2

I am trying to send data to a login textbox but when I use 'send_keys' I get an error..

def wait_for_element(selenium, selenium_locator, search_pattern, wait_seconds=10):
    elem = None
    wait = WebDriverWait(selenium, wait_seconds)

    try:
        if (selenium_locator.upper() == 'ID'):
            elem = wait.until(
                EC.visibility_of_element_located((By.ID, search_pattern))
            )
    except TimeoutException:
        pass

    return elem

userid=os.environ.get('userid')
wait_for_element(selenium, "ID", 'username')
assert elem is not None
elem.click()
time.sleep(3)
elem.send_keys(userid)

tests\util.py:123: in HTML5_login elem.send_keys(userid) ..\selenium\webdriver\remote\webelement.py:478: in send_keys {'text': "".join(keys_to_typing(value)),


value = (None,)

def keys_to_typing(value):
    """Processes the values that will be typed in the element."""
    typing = []
    for val in value:
        if isinstance(val, Keys):
            typing.append(val)
        elif isinstance(val, int):
            val = str(val)
            for i in range(len(val)):
                typing.append(val[i])
        else:
          for i in range(len(val)):
         for i in range(len(val)):

E TypeError: object of type 'NoneType' has no len()

I have no clue why it is saying the element is of "NoneType" when I have it pass an assertion as well as click the element. I can even see it clicking the element when I run the test!

Austin
  • 33
  • 6

1 Answers1

1

This error message...

elem.send_keys(userid) ..\selenium\webdriver\remote\webelement.py:478: in send_keys {'text': "".join(keys_to_typing(value)), value = (None,)
TypeError: object of type 'NoneType' has no len()

...implies that send_keys() method encountered an error when sending the contents of the variable userid.

Though you have tried to use the variable userid, I don't see the variable userid being declared anywhere within your code block. Hence you see the error:

TypeError: object of type 'NoneType' has no len()


Solution

Initialize the userid variable as:

userid = "Austin"

Now, execute your test.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Oh, sorry. I forgot to include userid within the code i posted. I can assure you tho that userid has a string set to it. Will update the post. – Austin Dec 06 '19 at 15:31
  • 1
    Actually this was the issue.. I was assigned userid to ```userid=os.environ.get('userid')``` Seems something is wrong with this piece of code, thank you for your help! – Austin Dec 06 '19 at 15:38