Click On Bitmap

Introduction

Welcome to this tutorial on using the “Click On Bitmap” feature in WinTask. In this session, we will demonstrate how to utilize image recognition to interact with elements on a web page, specifically using the Submit button as an example.

Setting Up

Before we begin, ensure you have Google Chrome installed and set up for use with WinTask. We will maximize the browser window for this tutorial.

Recording the Task

  1. Start Recording: Open Chrome and navigate to the web form.
  2. Fill Form: Enter random information into the form fields.
  3. Stop Recording: Stop the recording once the data is entered.

Modifying the Script

Remove the Submit Button Click: In the recorded script, remove the syntax that automatically clicks the Submit button.

Using “Click On Bitmap”

  1. Access Menu: Go to the menu and click “Insert”, then “Click on”, and select “Image”.
  2. Wizard Setup: Open the Wizard, click the “Spy” button, and select your window.
  3. Capture Image: Capture the Submit button image and save it as “Submit Button”.
  4. Adjust Settings:
    • Path: Define the bitmap path.
    • Window: Set the window for recognition.
    • Position: Choose the click position (exact, within the window, or in a defined area).
    • Threshold: Set recognition threshold between 90 and 97.
  5. Verify Recognition: Click “Check” to ensure WinTask identifies the button on the screen.
  6. Insert Syntax: Paste the generated syntax into your script.

Running the Script

With the modified script, run your automation to see the result. WinTask should now automate the task using image recognition.

Detailed Explanation of ClickOnBitmap

The ClickOnBitmap function in WinTask simulates a click on a specified image. It is particularly useful for clicking icons that are images rather than standard Windows icons. For example, a custom-designed Cancel button. The function’s syntax is as follows:


ClickOnBitmap(<filename.BMP>,<button>,<action>[,InArea(<x>,<y>,<height>,<width>)[,<offset_x>,<offset_y>]])

Parameters:

  • filename.BMP: Path to the bitmap file.
  • button: Mouse button used (Left or Right).
  • action: Click type (single or double click).
  • InArea: Optional keyword to specify a search area.
  • x, y: Coordinates of the area’s top-left corner.
  • height, width: Dimensions of the search area.
  • offset_x, offset_y: Optional click offset from the image center.

Example Usage:


UseWindow(...)
ClickOnBitmap("C:\save\image.bmp", Left, Single, InArea(10, 50, 200, 300), 5, 5)

The function returns 0 on success, with various error codes indicating issues like the file not being found, color depth mismatch, or the bitmap not being located on the screen. The script execution does not stop in case of an error, allowing for continued automation even if the bitmap is not found.

Thank you for following this tutorial. Please leave comments for any specific tutorials you would like to see next.

Reference Code


StartBrowser("CH", "https://wintask.net/excel-to-web-form/",3)
UsePage("Excel to Web Form Tutorial - WinTask")
    SelectHTMLItem("SELECT[NAME='area']", "France")
    WriteHTML("INPUT TEXT[NAME='firstname']", "Pierre")
    WriteHTML("INPUT TEXT[NAME='lastname']", "Troudout")
    WriteHTML("INPUT TEXT[NAME='email']", "pierre@wintask.net")
    WriteHTML("INPUT TEXT[NAME='phone']", "077123123123")
UseWindow("CHROME.EXE|Chrome_WidgetWin_1|Excel to Web Form Tutorial - WinTask - Google Chrome",1)
ClickOnBitmap("C:\Users\Paul\Desktop\SubmitButton.bmp", left, single)
CloseBrowser()