Python Forum
TypeError: object of type 'NoneType' has no len() - what do it mean?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: object of type 'NoneType' has no len() - what do it mean?
#1
note: i have another forum topic going with the same project. I've whited out a few lines to I can continue to practice until i resolve the other forum issue.
https://python-forum.io/Thread-Permissio...nied-error
In the mean time i have another issue which i'm raising here. Please be patient, i'm trying to learn and have a long long way to go with my development.

I have my code able to successfully look at a spreadsheet with a mix of working and not working username and passwords. The code will successfully add the username and password for the 4 different test cases but then gives the error message

TypeError: object of type 'NoneType' has no len

C:\Python37\python.exe C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py
test is passed
test failed
test failed
test failed
Traceback (most recent call last):
  File "C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py", line 24, in <module>
    driver.find_element_by_name("userName").send_keys(username)
  File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 478, in send_keys
    {'text': "".join(keys_to_typing(value)),
  File "C:\Python37\lib\site-packages\selenium\webdriver\common\utils.py", line 150, in keys_to_typing
    for i in range(len(val)):
TypeError: object of type 'NoneType' has no len()
I'm guessing this is because of the loop I have? to it looks at the first 5 rows in my spreadsheet which have conditions and then hits the 6th row which is blank? Would my assumption be right?

If so what do i need to change?

I'm assuming i need to add some other condition to the following line
for r in range(2, rows):
    username = XLUtils.readData(path, "Sheet1", r, 1)
    password = XLUtils.readData(path, "Sheet1", r, 2)
Here is the code from the module of interest

from selenium import webdriver
import unittest
import XLUtils
 
profile_path = 'C:/FireFoxProfile'
profile = webdriver.FirefoxProfile(profile_path)
driver = webdriver.Firefox(firefox_profile=profile_path)
driver.implicitly_wait(5)
driver.get('http://www.demoaut.com/')
driver.maximize_window()
 
[b]path = "C://FireFoxProfile/login1.xlsx"[/b]
 
rows = XLUtils.getRowCount(path, 'Sheet1')
 
for r in range(2, rows):
    username = XLUtils.readData(path, "Sheet1", r, 1)
    password = XLUtils.readData(path, "Sheet1", r, 2)
 
    driver.find_element_by_name("userName").send_keys(username)
    driver.find_element_by_name("password").send_keys(password)
 
    driver.find_element_by_name("login").click()
 
    if driver.title == "Find a Flight: Mercury Tours:":
        print("test is passed")
        XLUtils.writeData(path, "Sheet1", r, 3, "test passed")
    else:
        print("test failed")
        XLUtils.writeData(path, "Sheet1", r, 3, "test failed")
 
    driver.find_element_by_link_text("Home").click()
 
    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
 
if __name__ == '__main__':
    unittest.main(verbosity=2)
Reply


Messages In This Thread
TypeError: object of type 'NoneType' has no len() - what do it mean? - by leviathan54 - Apr-20-2019, 01:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 383 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 502 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 738 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 986 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,346 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,490 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  TypeError: 'float' object is not callable #1 isdito2001 1 1,074 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,088 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  declaring object parameters with type JonWayn 2 889 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,437 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020