Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
9 years ago

python run-time error "method is not callable"

Hi All my aim is  to get the data from  the excel and execute the method which given in the excel but am facing the Python Run-time Error method cannot be callable for the lines 4 and 6

 

def ReadDataFromExcel():
  xl = Sys.OleObject["Excel.Application"]
  book = xl.Workbooks.open("C:\\DriverSheet.xls")
  TCSheet = book.Worksheets("TestCases")
    #TCSheet = WorkBook.worksheets("TestCases")
  TSSteps = book.Worksheets("TestSteps")
  
  TCRows =   TCSheet.UsedRange.Rows.Count
  for i in range(2,TCRows):
    if TCSheet.cells(i,2).Value == "Yes":
      SlNo = TCSheet.cells(i,1).Value
      Module = TCSheet.cells(i,2).Value
      TestCase = TCSheet.cells(i,3).Value
      Duration = 0
      TSRows = TSSheet.UsedRange.Rows.Count
      for j in range (2,TSRows):
        if((TSSheet.cells(j,1).Value == TestCase) and ( TSSheet.cells(j,4).Value == "Yes")):
          Flag = Flag+1
          if Flag ==1:
           Report.CreateTestCaseReportHeader(TestCase)
        TSCols =   TSSheet.UsedRange.Columns.Count
        TSData = ""
        for k in range (5 , TSCols):
            TSData = TSData & TSSheet.cells(j,k).Value & ";"
    Parameter = Split(Tsdata,";")
    BeforeTime = aqDateTime.Time()
    Execute.TSSheet.cells(j,3).value
    AfterTime = aqDateTime.Time()
    Duration = Duration + aqDateTime.TimeInterval(AfterTime,BeforeTime)

Can anyone help me out

  • Worksheets and Cells are collections, and in Python you need to use .Item[] to access the collection items. So change

    book.Worksheets("TestCases")
    TCSheet.cells(i,1)

    to

    book.Worksheets.Item["TestCases"]
    TCSheet.cells.Item[i,1]

    Also check the documentation for Python specifics in TestComplete.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Worksheets and Cells are collections, and in Python you need to use .Item[] to access the collection items. So change

    book.Worksheets("TestCases")
    TCSheet.cells(i,1)

    to

    book.Worksheets.Item["TestCases"]
    TCSheet.cells.Item[i,1]

    Also check the documentation for Python specifics in TestComplete.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      HKosova Thanks For the info am facing an error when am trying to append and split the parameters

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        I tried your code with Excel 2010, and the Cell object has two "Value" properties:


        Value(RangeValueDataType)
        Value2

         

        Try Value2 instead of Value and see if that works.