Forum Discussion

Manojrsr's avatar
Manojrsr
Contributor
8 years ago

How to Retrieve data from CSV File

Hi Team,

Im using CSV File to read data and pass value to Script.

CSV File as :

UserNamePassword
devarajulu.m123456
manoj.sPassword1

 

I need to pass value Username password for first iteration of data and second so on.,

how to retrieve cell value in CSV. can you provide example script.

 

 

function main()
{
var browser,page,form,Driver;
Browsers.Item(btFirefox, "", Browsers.pX64).Run("AppURL");
browser = Aliases.browser;


Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv");

while(!Driver.EOF())
{
page=browser.pageWelcomeToReferralvalet8;
loginClick(page,browser);
page = browser.pageWelcomeToReferralvalet7;
adminLogin(page,form,browser,Driver);

Driver.Next();

}

}

 

function adminLogin(page,form,browser,Driver)
{
var textbox;
var table;
var panel;
page.Wait();
form = page.formAspnetform;
textbox = form.textboxTxtusername;
textbox.Click(78, 12);
textbox.SetText(Driver.Value(1));

}

 

 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Instead of what you have, do this:

    function main()
    {
    var browser,page,form,Driver;
    Browsers.Item(btFirefox, "", Browsers.pX64).Run("AppURL");
    browser = Aliases.browser;
    
    
    Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv");
    while(!Driver.EOF()) {
        page=browser.pageWelcomeToReferralvalet8;
        loginClick(page,browser);
        page = browser.pageWelcomeToReferralvalet7;
        adminLogin(page,form,browser,Driver.Value('UserName'));
        Driver.Next();
        }
    }
    
    function adminLogin(page,form,browser,userName)
    {
    var textbox;
    var table;
    var panel;
    page.Wait();
    form = page.formAspnetform;
    textbox = form.textboxTxtusername;
    textbox.Click(78, 12);
    textbox.SetText(userName);
    }

    There's no need to pass the driver object to your other function, just send in the value of the column.

    Note also that I changed the call to Driver.Value to use the column header rather than the index (the index you had before was incorrect anyways since the username is column 0, not column 1).

     

    Technically speaking, what you did before SHOULD have worked with the only problem being that you would be sending the password as the username.  So, I guess the next question is... with what you had before... what was NOT working?

    • Manojrsr's avatar
      Manojrsr
      Contributor

      I have updated my script as you said.

      but Error Occurs "Item cannot be found in the collection corresponding to the requested name or ordinal"

       

       

      function adminLogin(page,form,browser,Driver,userName)
      {
      var textbox;
      var table;
      var panel;
      page.Wait();
      form = page.formAspnetform;
      textbox = form.textboxTxtusername;
      textbox.Click(78, 12);
      textbox.SetText(userName);

      }

       

      function main()
      {
      var browser,page,form,Driver;
      Browsers.Item(btFirefox, "", Browsers.pX64).Run("http://sysnetportal1/RVTesting_1/");
      browser = Aliases.browser;

      Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv")

      while(!Driver.EOF())
      {
      page=browser.pageWelcomeToReferralvalet8;
      loginClick(page,browser);
      page = browser.pageWelcomeToReferralvalet7;
      adminLogin(page,form,browser,Driver.Value('UserName'));

      Driver.Next();

      }

      }

       

       

      I have attached my CSV file for your reference:

       

      When i tried to print column name using script :

      temp=DDT.CurrentDriver.ColumnName(0);
      Log.Message("Value of column is " + temp);

       

      Message shown as "Value of column is UserName_Password ", why both column has combined

      when i tried to access DDT.CurrentDriver.ColumnName(1);

      Again Error occurs as "Item cannot be found in the collection corresponding to the requested name or ordinal"

       

      Can you please on this, to retrieve my Username and password in CSV file.