How to check file extensions using QTP

Updated On Aug 8, 2014 by

Using QTP, we want to validate whether the particular image on a web page is .jpg, .gif, .bmp or any other extension.


  1. We will take the example of Mercury demo application demo application page
  2. The image to be checked is shown in red ellipse above.
  3. Now “Object spy” on the object.How to check file extension using QTP
  4. Find the property containing filename. Usually the name of the property would be file name itself. The value for this case is featured_destination.gif.
  5. Put this value into a array using GetTO property.
  6. Now make use of split function with . (dot) as delimiter.
  7. The last value of the array would be your required file extension. Usually the 2nd value inside an array would be the file extension, but in case developer assigns the name as featured.destination.gif [Notice the two dots] then it might create a problem that’s why always take the last value of the array.

Here is the script for the process given above:

Dim filename, arrfile

'Put filename into the array

filename =  Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Featured Destination:").GetTOProperty("file name")

' Split using "." as delimiter

arrfile = split(filename,".")

msgbox arrfile(Ubound(arrfile))

Welcome new readers: Download the Free eBook!

Ankur JainI am Ankur Jain, the owner of LearnQTP and founder of a software organization. This site is run, maintained and updated by me and my team. Feel free to take a look around, you may want to start with What is QTP? 

You can connect with me on my Google+ page. 

Please enter your first name and email address below to instantly download the eBook on Optimizing QTP Scripts. In future, we will make sure you get new tips & tricks on QTP delivered direct to your email box.

Share This:


  1. Rajasekhar

    Nice example…

  2. Venu

    I just want to know where can I get new version of QTP user guide through net.

  3. Anunay

    @Michelle – A better idea is to use descriptive programming with regular expressions. Even with thsi if you are unable to continue, the only way left is using the index or location properties of the object plus the Smart Identification being enabled. However, i do not believe you would ever come to a situation where QTP is unable to identify an object. You may either be missing an addin or something wrong with the software installation or other environment issues.

  4. Michelle

    How to proceed with QTP when QTP doesn’t identify the object? When a object is not being recognized by QTP, what is the work around so that you can continue with automation?

  5. kami


    Iam new to testing….i want to know how to do functional testing of a website using QTP…i mean how to test a website with navigation ….i face this question in interviews so plz let me know the proper process….

  6. subbareddy

    i think Venu is right , for example , MS Excel 2007, extension is .xlsx .
    Also, Navan –> How would you use Mid function when you donot know the index to start with as the file names varies.

  7. Venu Yalluri

    Navan, reading the last 3 characters using Mid will not work when the file extension is more than 3 characters

  8. Navan

    I think we can also go for regular expression for file name. Since the file extension is always the last three letters prefixed with a .(dot), we can also make use of mid functions.
    I think they will be more easy than using an array n then splitting it

    1. First take the string into a varible using GETROProperty(filename)
    2. Use mid function to read last three letters of string
    3. Display it / Use Msgbox / compare it with provided extensions

  9. Manoj Pant

    Do QTP supports a GUI application build using the QT libraray?

  10. Rahul

    Can any body describe “How to use keyword driven framework”?
    Please give an example of this…
    Thanks in advance……….

  11. Ankur

    @Prabas and Ajay: I think that would work only for File System Objects

  12. Ajay

    Praabas is also right…..
    Check with that function.

    Ajay Garg

  13. Ajay

    Very Good example.

  14. 123

    Good Example

  15. Praabas

    we can also use GetExtensionName(agr) metod to find the extension of file.Am I right?

  16. shilpi


    My self Shilpi & I want to learn QTP online…Can you please help me out for this…

    Thaks & Regards

  17. jay

    Good example, short and good!

  18. Shrini Kulkarni


    I would like to have a email conversation with you .. kindly reply me at

    Shrini Kulkarni

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>