Apr-20-2019, 05:39 AM
(This post was last modified: Apr-20-2019, 05:58 AM by leviathan54.)
@Skaperen When you say it has no length..
We are talking about this line?
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
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 1Module 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)