18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Reading file name from UI

manasa.msmanasa.ms Members
edited November -1 in Sahi - Open Source
Hi,
In my Script am reading the data from CSV file,, now i have included the CSV file name in my script, i want to read that CSV file name through the Prompt, for that am using "prompt" API. Am able to enter the file name in the propmt but am not able to store the entered file name to any variable. So i want to know how to read the file names or any other variables dynamically.. Can anybody help me on this..

Comments

  • here is the sample code
    var $csvpath;
    $csvpath = _prompt("enter the csv file name");
    _debug($csvpath);
    its displaying "null"
  • SumitraSumitra Members
    Hi manasa.ms,

    You can try this:
    <browser>
    function promptForCsvPath(){
        promptValue = _sahi._prompt("Enter the csv path");
    }
    </browser>
    
    function getFile(){
        var $value = null; 
        _call(promptForCsvPath());
        _set($value, promptValue);
        return $value;
    }
    
    var $csvPath = getFile();
    _alert($csvPath);
    

    Let me know if you face any problem.

    Regards
    Sumitra
  • Hi Sumithra
    That code is working thanks a lot...
    now i want to know how to write data into CSV file , am making use of _writeCSVFile(array2d, filePath) api , but it is writing each individual character into a cell.

    Ex:
    part of my code is like this :

    var $data=_readCSVFile("/home/trainee/sahi/userdata/scripts/csv_16th/test_csv_new_url.csv");
    $keyword=$data[1][0];
    _writeCSVFile($data[1][0],"/home/trainee/Desktop/write.csv")

    when i run this code it will run successfully but the data (in this case its "url") will be printed in csv file like
    u
    r
    l

    Can you help me on how to print that "url" as a single value in a cell of CSV file. Here am saving a openoffice spreadsheet with .csv extension and making use of it as CSV file
This discussion has been closed.