SQA(Software Quality Assurance Automation with QTP – easy function to click on any image

Hello. If you remember, I showed you how to create a Click Any Link function a little while ago. You can find the tutorial here. Now that we know how to do that, we can create any function in the same manner. Today, I will show you a click on any image function that can take any single or multiple property values.

  Function  fun_Click_AnyImage(strProperties)
  Set objBrowserPage = Browser("Index:=0").Page("title:=.*")
      arrStrProperties = Split(strProperties, ",")
      arrCount = uBound(arrStrProperties) + 1
     If arrCount = 1 Then
         ElseIf arrCount = 2 Then    
         strProperty1 = arrStrProperties(0)
         strProperty2 = arrStrProperties(1)
         objBrowserPage.Image(strProperty1, strProperty2).highlight
         objBrowserPage.Image(strProperty1, strProperty2).Click
         ElseIf arrCount = 3 Then
         strProperty1 = arrStrProperties(0)
         strProperty2 = arrStrProperties(1)
         strProperty3 = arrStrProperties(2)
         objBrowserPage.Image(strProperty1, strProperty2, strProperty3).highlight
         objBrowserPage.Image(strProperty1, strProperty2, strProperty3).Click
     End If
  End Function

1. Copy the function into your script

2. Let's practice by clicking on the image above. Click on object spy and find a unique property. In this case I will use the title QTP test image.

3. Now call the function like this:

fun_Click_AnyImage "title:=QTP test image"

4. If you want to call this function with multiple properties, you can do that as well like this:

fun_Click_AnyImage "title:=QTP test image,Index:=0"

Amazing right? Please let me know if this function helped you out! Post all of your comments below 🙂

Pin It on Pinterest

Clef two-factor authentication