TypeError: string indices must be integers | Selenium Python Forum
K
Kam Posted on 21/05/2020
Following code was working for a month without issue. Before that 3 test cases with different Browsers were working fine


self = <Testcases.test_login.Test_login object at 0x0000027D34DD4E08>
argVals = {'Browser': 'Chrome', 'Runmode': 'Y', 'password': 'Selenium@542', 'userName': 'Python5@gmail.com'}

    @pytest.mark.parametrize('argVals',dataUtility.getTestData("Login", Constants.HYBRID_XLS_FILE))
    def test_loginTest(self,argVals):
        dataRunMode = argVals[Constants.RUNMODE_COL]
        print("dataRunMode is :    ", dataRunMode)
        print("dataRunMode is :    ", argVals)
    
        testRunModeStatus = dataUtility.isRunable("Login", Constants.HYBRID_XLS_FILE)
        print("testRunMode is :    ", testRunModeStatus)
    
        if (testRunModeStatus):
            if (dataRunMode == Constants.RUNMODE_YES):
                print("dataRunMode == Constants.RUNMODE_YES  ", testRunModeStatus)
                with allure.step("test being executed "):
    
                    #ds = DriverScript.executeKeywords("Login", Constants.HYBRID_XLS_FILE, argVals)=================================
>                   ds.executeKeywords("Login", Constants.HYBRID_XLS_FILE,argVals)

Testcases\test_login.py:39: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Drivers\DriverScript.py:52: in executeKeywords
    getattr(y,keyword)(executer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Keyword.GenKeywords.GenKeyword object at 0x0000027D34DD4808>

    def openBrowser(self):
        with allure.step("Opening Browser"):
            #browserName = self.data[self.dataKey]
>           browserName=self.data[self.dataKey]
E           TypeError: string indices must be integers

Keyword\GenKeywords.py:67: TypeError

===========================================DRIVER SCRIPT============================================================

from Reading import XLSreader

from Utils import dataUtility

from Utils import Constants
import sys

from Keyword.GenKeywords import GenKeyword

global xls


class DriverScript:
def executeKeywords(self,testcaseName,xlspath, testdata):

executer=GenKeyword()
xls = XLSreader(xlspath)

row = xls.rowCount(Constants.KEYWORDSHEET)
for rNum in range (1,row):
tcid = xls.getCellDatabyColname(rNum, Constants.TCID_COL, Constants.KEYWORDSHEET)
if (tcid == testcaseName):
keyword = xls.getCellDatabyColname(rNum, Constants.KEYWORD_COL,Constants.KEYWORDSHEET)
objectKey = xls.getCellDatabyColname(rNum, Constants.OBJECT_COL,Constants.KEYWORDSHEET)
dataKey = xls.getCellDatabyColname(rNum, Constants.DATA_COL, Constants.KEYWORDSHEET)
#dataKey = xls.getCellDatabyColname(rNum, Constants.DATA_COL, Constants.KEYWORDSHEET)
#objectData = xls.getCellDatabyColname(rNum, Constants.OBJECT_COL,Constants.KEYWORDSHEET)
print ("Key word is : ", keyword)
print ("object key is : ", objectKey)
print ("data Key is : ", dataKey)


#call the function that is with the same name as of Keyword
#\executer.set_data(dataKey)
#executer.set_dataKey(keyword)
#executer.set_objKey(objectData)

executer.set_data(dataKey)
executer.set_dataKey(keyword)
executer.set_objectKey(objectKey)


y=getattr(sys.modules[__name__],'GenKeyword')
print ("Y IS : ", y)
print ("KEY WORD : ", keyword)
print ("Y attr IS : ", getattr(y,keyword))
getattr(y,keyword)(executer)

=====================================CONSOLE OUTPUT FOR DRIVER SCRIPT===========================

---------------------------- Captured stdout setup ----------------------------
***************************Start Test Case ************************************
production
URL is : https://www.zoho.com/
XLS PATH IS : C:\\eclipse-workspace2\\Hybrid-Framework\\TestResources\\zohoPyHyb.xlsx
XLS READER PATH IS : C:\\eclipse-workspace2\\Hybrid-Framework\\TestResources\\zohoPyHyb.xlsx
---------------------------- Captured stdout call -----------------------------
dataRunMode is : Y
dataRunMode is : {'Runmode': 'Y', 'Browser': 'Chrome', 'userName': '************@gmail.com', 'password': '***********'}
XLS READER PATH IS : C:\eclipse-workspace2\Hybrid-Framework\TestResources\zohoPyHyb.xlsx
Y
run mode in YES in isRunable Y
testRunMode is : True
dataRunMode == Constants.RUNMODE_YES True
XLS READER PATH IS : C:\eclipse-workspace2\Hybrid-Framework\TestResources\zohoPyHyb.xlsx
Key word is : openBrowser
object key is :
data Key is : Browser
Y IS : <class 'Keyword.GenKeywords.GenKeyword'>
KEY WORD : openBrowser
Y attr IS : <function GenKeyword.openBrowser at 0x0000027D345480D8>
======================== 1 failed, 2 skipped in 0.73s =========================

 

=============================================GEN KEY WORDS===========================


from Utils import Constants
from selenium import webdriver
import configTest
import time
from _overlapped import NULL

global prodProp
global envProp

global objKey
global dataKey
global data

from allure_commons.types import AttachmentType
import allure
import logging

import sys
from _datetime import datetime


class GenKeyword:
'''
**************************************INITIALIZE PROPERTY FILE **********************************************************
'''
def __init__(self):
self.logger = logging.getLogger()
self.logger.setLevel(logging.INFO)

self.envProp = configTest.envProp
self.prod = configTest.prod

self.driver =NULL

'''
***************************************Setter to SET DATA*********************************************************
'''
def set_objectKey(self,OK):
self.objKey=OK


def set_dataKey(self,DK):
self.dataKey=DK

def set_data(self,testdata):
self.data=testdata




'''
**************************************KEY WORDS *******************************************************************
'''
def openBrowser(self):
with allure.step("Opening Browser"):
#browserName = self.data[self.dataKey]
browserName=self.data[self.dataKey]
if(browserName == Constants.CHROME):
path = Constants.CHROME_DRIVER
self.driver = webdriver.Chrome()

elif(browserName == Constants.FIREFOX):
path = Constants.FIREFOX_DRIVER
self.driver = webdriver.Firefox(executable_path=path)

 

=================================================PIP LIST=========================

Package Version
--------------------- ----------
allure-pytest 2.8.13
allure-python-commons 2.8.13
atomicwrites 1.3.0
attrs 19.3.0
certifi 2020.4.5.1
chardet 3.0.4
colorama 0.4.3
et-xmlfile 1.0.1
fixture 1.5.11
idna 2.9
importlib-metadata 1.6.0
jdcal 1.4.1
more-itertools 8.2.0
openpyxl 3.0.3
packaging 20.3
pip 20.1.1
pluggy 0.13.1
py 1.8.1
pyjavaproperties 0.7
pyparsing 2.4.7
pytest 5.3.5
pytest-dependency 0.5.1
pytest-html 2.1.1
pytest-metadata 1.9.0
pytest-runner 5.2
requests 2.23.0
selenium 3.141.0
setuptools 46.4.0
six 1.14.0
urllib3 1.25.8
wcwidth 0.1.9
wheel 0.34.2
xlrd 1.2.0
xlwt 1.3.0
zipp 3.1.0

==================================================================

 




0
09914040666 Replied on 22/05/2020

Hey, 

Kindly please zip the project and share

 


K
Kam Replied on 24/05/2020

issue is resolved 

Error was :  executer.set_data(dataKey)

instead executer.set_data(testdata)


0
09914040666 Replied on 16/07/2020

Hey, 

 

Thank you for the information you solved the error