In this tutorial, we will build a bot to change the background for multiple car images. Here is the use case we are addressing: A car dealer has pictures of his car inventory with non-uniform backgrounds. He wants to remove the background for each picture and update it to have a uniform branded background. Let's see how we can build a bot in Automation 360 to update all the images.
This bot can be used to update/remove background images for other use cases such as:
- Updating employee profile pictures
- Media houses use images without a background in different editorial sections
- Marketing teams use it to update image backgrounds to suit different ads based on the context
Here is the data setup required to build this bot:
- Download the folders with different car images here. Here are the pictures for your reference:
- Download the background template image here.
Let's start building the bot by following the steps as shared below:
- Log in to the Automation 360 Control Room.
- Go to Bots - My bots, and click the Create a bot icon.
- In the Name field, enter 'Car Images Background Update Bot'
- Click Create & Edit.
- In the Actions pane, click Variables to create the following new variables:
- Name - sURL, Type - String, Default value - https://www.slazzer.com/upload. This is the website we will use to remove the background and add our standard background template image.
- Name - dictImageFile, Type - Dictionary and Subtype - String. - This variable will hold the file names and extension as a key-value pair. You can use the 'name' key to access the file name and 'extension' key to access the file extension.
- Name - sInputFolderPath, Type - String. This variable will contain the folder path in your local system which contains folders with pictures of different cars
- Name - sFolderName, Type - String. This variable will contain the foldername (sub folder) within the input folder path sInputFolderPath
- Name - sBGImagePath, Type - String. This variable will contain the background template image to be added to each car image.
- Name - sOutputFolderPath, Type - String. This variable will contain the folder path in your local system created by the bot and will be updated with new uniform car images.
- From the Action pane, select Browser - Launch Website.
- In the URL field, enter $sURL$
- In Browser field, select Google Chrome
- Now we will loop through all the sub-folders folders within the given folder path.
- From the Action pane, select Loop.
- In the Iterator field, select For each folder in a folder
- Enter the folder path as $sInputFolderPath$
- In ‘Assign folder name to this variable’ field, select ‘sFolderName - String’
- In the Iterator field, select For each folder in a folder
- From the Action pane, select Loop.
- As we are looping through each sub folder, let's create the sub folders with the same name as the car names shown in the data setup) within the output path.
- From the Action pane, select Folder - Create. This step will create the folders to store the updated images
- In the folder field, Enter the path as $sOutputFolderPath$$sFolderName$. This step will create folders within the output folder path
- From the Action pane, select Folder - Create. This step will create the folders to store the updated images
- The next step is to loop through all the files within each folder so that the bot can pick up each image and upload it to Slazzer for updating it with standard background template image.
- From the Action pane, select Loop.
- In the Iterator field, select For each file in folder
- Enter the folder path as $sInputFolderPath$$sFolderName$
- In the ‘Assign file name and extension to this variable’ field, select ‘dictImageFile - Dictionary of Strings’
- In the Iterator field, select For each file in folder
- From the Action pane, select Loop.
- We will add Delays at each step to ensure the website is able to load and process the images.
- From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- While building the bot, I have noticed that the Slazzer retains the image from a previous transaction. To handle this scenario let's add an If condition to click on the ‘X' mark if the earlier image is retained. When the Slazzer is launched the first time with the URL https://www.slazzer.com/upload, it will look like this:
While trying to upload a new image, if the page retains an earlier image, it will look like this. In this case, we want to click on 'X’ to remove the older image.
- From the Action pane, select If
- Select Condition - Object
- In the Object detail field, click Window and select the Slazzer webpage
- Click Capture Object, identify the X symbol as shown above (We just want to check that this object is present)
- Within the If loop, From the Action Pane, select Recorder - Capture
- In Object detail, Select Window and Identify the browser instance with Slazzer website open
- Click on Capture Object and select the X symbol as shown above
- Select Action - Left Click (Double check the properties shown in the screenshot below if you notice if the bot is not performing intended steps)
- Click Save.
- Now that the earlier image is removed from the display and the page looks like this
- From the Actions Pane, select Recorder - Capture, to click on the 'Upload Image' icon. (outside the If loop) but within the inside Loop
- In Object detail, Select Window and Identify the browser instance with Slazzer website open
- Click on Capture Object and select the Upload Image icon as shown below
- Select Action - Left Click
- From the Actions Pane, select Recorder - Capture, to click on the 'Upload Image' icon. (outside the If loop) but within the inside Loop
- Add Delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- ‘Open Dialog’ is displayed to select the image to be uploaded to the website.From the Actions Pane, select Recorder - Capture, to enter the image path.
- In Object detail, Select Window and Identify the Open Dialog
- Click on Capture Object and select the Field - File Name text box as shown below
- Select Action - Set Text
- Enter Keystrokes as $sInputFolderPath$$sFolderName$$dictImageFile{name}$
.
$dictImageFile{extension}$. This path will fetch one image for each iteration within the loop
- Enter Keystrokes as $sInputFolderPath$$sFolderName$$dictImageFile{name}$
- Once the path is entered, next step is to click on ‘Open’ button. From the Actions Pane, select Recorder - Capture
- In Object detail, Select Window and Identify the Open Dialog
- Click on Capture Object and select the Open button as shown below
- Select Action - Click
- Add a delay of 3 seconds for the image to be loaded to the website. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- Image is loaded to the website and the background is removed as seen below, but we still have to add our branded background template image. To add the background image, click on Edit Image button.
- From the Actions Pane, select Recorder - Capture
- In Object detail, Select Window and identify the slazzer website instance
- Click on Capture Object and select the Edit Image button
- Select Action - Click
- From the Actions Pane, select Recorder - Capture
- Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- Once the Edit Image button is clicked, a dropdown will display as shown below, click ‘Edit Preview’ (Image BG9)
- From the Actions Pane, select Recorder - Capture
- In Object detail, select Window and identify the slazzer website instance
- Click on Capture Object and identify the object Edit Preview. In the attribute, HTML InnerText, retain the text ‘Edit Preview’ and add an asterisk instead of the exact dimension, as they change for different images. So, the attribute value will look this: Edit Preview*
- Select Action - Click
- From the Actions Pane, select Recorder - Capture
- Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 5, Time Unit as Seconds
- A new modal opens up where you can select the standard background template image.
- From the Actions pane, select Recorder - Capture
- In Object detail, select Window and identify the slazzer website instance
- Click on Capture Object and identify the object Upload Image.
- Select Action - Left Click
- Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- ‘Open Dialog’ is displayed to select the standard background template image to be uploaded to the website.
- From the Actions pane, select Recorder - Capture, to enter the image path.
- In Object detail, Select Window and identify the Open Dialog
- Click on Capture Object and select the Field - File Name text box as shown below
- Select Action - Set Text
- Enter Keystrokes as $sBGImagePath$
- From the Actions pane, select Recorder - Capture, to enter the image path.
- Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- Once the path is entered, the next step is to click on the ‘Open’ button. From the Actions pane, select Recorder - Capture
- In Object detail, select Window and identify the 'Open Dialog'
- Click on Capture Object and select the Open button
- Select Action - Click
- Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, enter Delay as 3, Time Unit as Seconds
- Now you can see our car image has a standard background. Click on the Download button.
- From the Actions pane, select Recorder - Capture
- In Object detail, select Window and identify the slazzer website instance
- Click on Capture Object and select the Download button
- Select Action - Click
- From the Actions pane, select Recorder - Capture
- Now the updated car image is downloaded to your local system. Let’s get the browser back to its initial state before we process the next image. Enter URL https://www.slazzer.com/upload in the address bar and press Enter key.
- From the Actions Pane, select Recorder - Capture, to enter the URL mentioned above.
- In Object detail, Select Window and identify the Open Dialog
- Click on Capture Object and select the Address Bar
- Select Action - Set Text
- Enter Keystrokes as
https://www.slazzer.com/upload
>ENTER]
- Enter Keystrokes as
- From the Actions Pane, select Recorder - Capture, to enter the URL mentioned above.
- We will add a delay to give the website a few seconds to download the updated image. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
- As the images download to ‘My Downloads’ folder, let's move it to ‘Output folder’ and maintain a similar folder structure as ‘Input folder’ from which we passed the car images to the bot.
- From the Actions pane, select File - Copy
- Enter the source file as
D:<username>My Downloadsslazzer-edit-image.png
(Add the correct path according to your settings), replace <username> by your user name - Enter the Destination as $sOutputFolderPath$$sFolderName$$dictImageFile{name}$
.png
Object detail, This path will create the same folder structure as ‘Input folder’
- Enter the source file as
- From the Actions pane, select File - Copy
- As the slazzer website downloads all the updated car images with the same name, we want to ensure that we delete the image from ‘My Downloads’ folder.
- From the Actions pane, select File - Delete
- Enter the file as
D:<username>My Downloadsslazzer-edit-image.png
(Add the correct path according to your settings), replace <username> by your user name
- Enter the file as
- From the Actions pane, select File - Delete
- This will be our final step which is outside the loop. Before we complete the bot, lets close the slazzer website instance.
- From the Actions Pane, select Simulate keystrokes- Simulate keystrokes
- Enter the file as
D:<username>My Downloadsslazzer-edit-image.png
(Add the correct path according to your settings), replace <username> by your user name - Select Window and identify the browser instance with slazzer website.
- Keystrokes - Enter keystrokes here or use the on-screen keyboard, Enter rCTRL DOWN]
w
iCTRL UP]
- Enter the file as
- From the Actions Pane, select Simulate keystrokes- Simulate keystrokes
- Your car image background update bot is ready.