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?
#4
@Skaperen When you say it has no length..
We are talking about this line?
for r in range(2, rows):
So i need to be able to say do rows until there is no condition?

Here is my entire code - i've realigned the code so it points to line 20 where the error message. I've also added comments to make it easier to understand

Traceback (most recent call last):
  File "C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py", line 22, 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()

Process finished with exit code 1
Module DataDrivenTestCase
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()

path = "C://FireFoxProfile/login1.xlsx"

rows = XLUtils.getRowCount(path, 'Sheet1')

# check rows in spreadsheet to obtains username and password and then
# insert username and password into  website
for r in range(2, rows+1):
    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 login is successful then check website is on right page and pass/fail test
    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")
#return to homepage and insert password/username for next row in spreadsheet
    driver.find_element_by_link_text("Home").click()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

if __name__ == '__main__':
    unittest.main(verbosity=2)
This is the only other module i have - this module looks at the spreadsheet and determines the max row and column

import openpyxl

def getRowCount(file, sheetName):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return(sheet.max_row)

def getColumnCount(file, sheetName):
    workbook = openpyxl.load.workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return(sheet.max_column)

def readData(file, sheetName, rownum, columnno):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return sheet.cell(row = rownum, column = columnno).value

def writeData(file, sheetName, rownum, columnno, data):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    sheet.cell(row=rownum, column=columnno).value = data
    # workbook.save(file)
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 481 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 583 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 800 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,112 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,492 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,622 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  TypeError: 'float' object is not callable #1 isdito2001 1 1,122 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,372 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  declaring object parameters with type JonWayn 2 934 Dec-13-2022, 07:46 PM
Last Post: JonWayn
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,531 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