Forum Discussion

EkremMese1's avatar
EkremMese1
Contributor
6 months ago

Item cannot be found in the collection corresponding to the requested name or ordinal

I created a test with scripting. Everything was working fine. 

Then I decided to use a Data Driven Testing approach with an excel file. 

My code started to give me the error in the caption. 

Here is my code: 

function search_with_loop(){
  DDT.ExcelDriver("Z:\\MeseE\\TestData_EIDSS_V7.xlsx", "Person_Search")
  DDT.CurrentDriver.DriveMethod("SearchPerson.search_for_existing_record")
}


/*

function search_for_existing_record(){
  
  //store the logs in related folders
  Log.AppendFolder(DDT.CurrentDriver.Value("Last_Name"));
  Log.Message(DDT.CurrentDriver.Value("Last_Name") + " here");
  //Log.AppendFolder("Solomatyn");  
  
  navigate_person_search_form();
  browser = Aliases.browser;
  browser.BrowserWindow.Maximize();
  let form = browser.pagePersonEidss.formPersonsearchform;
  
  let textbox = form.textboxLastName;
   
  //wait textbox to be enabled
  //textbox.WaitTypeName(textbox,2000);
  
  Log.Message(textbox.Exists);
  textbox.WaitProperty("Enabled", true, 2000);
  
  
  textbox.Click();
  
  textbox.SetText(DDT.CurrentDriver.Value("Last_Name"));
 
  //textbox.SetText("Solomatyn");
  
  form.buttonSearchbutton.ClickButton();
  aqObject.CheckProperty(form.lastNameLabelInGrid, "contentText", cmpEqual, DDT.CurrentDriver.Value("Last_Name"));
  
  //aqObject.CheckProperty(form.lastNameLabelInGrid, "contentText", cmpEqual, "Solomatyn");
  Log.PopLogFolder();
  
  browser.Close();


}
*/


function search_for_existing_record()
{
  navigate_person_search_form();
  Log.AppendFolder(DDT.CurrentDriver.Value("Person ID"));
  

  let page = browser.pagePersonEidss;
  page.Wait();
  let textbox = page.formPersonsearchform;

  let textbox3 = textbox.textboxPersonId;

  textbox3.WaitProperty("Enabled", true, 2000);
  textbox3.setText(DDT.CurrentDriver.Value("Person ID"));
  
  textbox.buttonSearchbutton.ClickButton();

  aqObject.CheckProperty(textbox.hyperLinkInGrid, "contentText" , cmpEqual, DDT.CurrentDriver.Value("Person ID"))
  
  
  
  Log.PopLogFolder(); 
  browser.Close();
}

Does anyone has an idea about it?


  • Hello again, 

    I just find out that the issue is cause by not closing the driver in the methods that I called in my code. 

    DDT.CloseDriver(DDT.CurrentDriver.Name);

    This line solved issue for me. 

    • Marsha_R's avatar
      Marsha_R
      Moderator

      If you use TestComplete debugging and step through the code, does the error still occur? If not, then there is a timing issue. To test that, put a long pause before the line that normally gives the error and run the test normally. Best practice in that case is to put a Wait function in rather than using the pause going forward.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    So the error "...requested name or ordinal" occurs only during playback, but not when debugging?

  • I have same error when I am debugging and when I am running my test. So both same.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If I'm reading this correct, your answer "Yes. But I don't spot any code error either :(" to my previous question, suggests there's no errors during debug?

    Now you are saying the error appears during playback and during debug? While debugging, where is the error occurring?

    • EkremMese1's avatar
      EkremMese1
      Contributor

      Sorry for confusion. When I said I don't spot any code error I meant that I have a problem, the code giving the error but I can't find it. Why I have this error? 

      And error is appears in same line which is line 12 below: 

      function searchForExistingRecord()
      {
        navigate_person_search_form();
          
        let page = browser.pagePersonEidss;
        page.Wait();
        let textbox = page.formPersonsearchform;
        let textbox3 = textbox.textboxPersonId;
        
        textbox3.WaitProperty("Enabled", true, 2000);
        
        let str = DDT.CurrentDriver.Value("PersonID");
        Log.Message(str);
        
        textbox3.setText(str);
        
        textbox.buttonSearchbutton.ClickButton();
       
        aqObject.CheckProperty(textbox.hyperLinkInGrid, "contentText" , cmpEqual, DDT.CurrentDriver.Value("PersonID"));
         
        browser.Close();
      }

       

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Why don't you comment out all lines of code accept for 12 and 13, to test if line 12 works?

        And you are calling the following methods before searchForExistingRecord?

        DDT.ExcelDriver(...)
        DDT.CurrentDriver.DriveMethod()

        Based on what you have provided, this is the results of it working by calling search_with_loop(),

         

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    So we have now established that there is nothing wrong with DDT. 

    The main issue, is the code that you have written to perform the automation test with the browser. Since we have no idea about the web application and what it does, you will have to diagnose the issue yourself - somewhere in this post Marsha_R mention inserting a delay. TC will just execute each line of code, regardless whether the UI control appears or not. So you will have instruct TC to wait for the UI control to appear, before providing any input. 

    Debug your script, to see how TC is interacting with your web application, and also see how your web application is responding. Also, do what Marsha_R has mentioned.