As promised in our previous blog post, this is part 2 of Tips and Tricks to make using Microsoft Power Automate more convenient! In our previous post, we covered tips #1 – #10. Today, we will be covering tips #11 – #20.
Tip #13 Select tab in a window
Tip #14 Select menu option in window
Tip #15 Focus text field and send keys
Tip #16 Run python script to validate email address format
Tip #18 Run javascript function on webpage
Tip #19 Extract data from webpage
For those of you who prefer to watch the video, you can have a look at the video below. If you prefer to read, just scroll down further for the article.
Power Automate Tip #11: Wait for window
If opening an application takes some time, we can use “wait for window” and focus it.
Firstly, search for the “wait for window” action.
In the “Wait for window” dialogue box, select the “find window” parameter as “By window UI element”, and turn on the “Focus window after it opens” option.
Running the flow will successfully open the desired window!
Power Automate Tip #12: Focus window
Assuming you have multiple windows to process, you can use “Focus window” to ensure you are working on the correct application.
In the “Focus window” dialogue box, in the “Window” dropdown menu, choose the window you want to focus on. In our example, it’s the “Window ‘Expenselt Standalone”.
This will ensure that the flow focuses on the application you are working on!
Power Automate Tip #13: Select tab in a window
Set your required tab in the “Select tab in a window” dialogue box. In our example in this case, the tab is “Window ‘My CRM (Sample App)’ > Tab item ‘Others’”
Running the flow will select the tab you need! In this case, it is the tab “Others”
Power Automate Tip #14: Select menu option in window
You can use the “Select menu option in window” action instead of configuring the flow to click the UI elements of the menu option you want to choose.
For example, I want to choose File > Clear fields. I can select the “Select menu option in window” action from the action pane, then select “Add UI element” in the “Select menu option in window” dialogue box. A new dialogue box “Tracking session” will open, asking you to add your UI elements. Select “clear fields” from the “file” drop down menu of the application and click “done”. Back at the “Select menu option in window” dialogue box, click Save.
Running the flow will allow you to automatically clear the fields!
Power Automate Tip #15: Focus text field and send keys
Let’s say you want to do a loop to type a value into an application (for example, like the picture below) followed by a tab to move to the next field. The “populate text field” action does not allow you to add shortcut keys. Instead, you can do so by using “send keys” action.
In the “Send keys” dialogue box, choose “misc”, then “tab” from the “insert special keys” drop down menu. Set the delay between keystrokes as 50.
In the flow, add an additional step – the “Focus on text field in window” action.
In the “Focus on text field in window” dialogue box, click the “text field” tab. Under the UI elements drop down menu, choose “Edit: ‘Other’”
The flow will then open the “Other” tab, focus on the “Generic 1” test field, and type “Test”, followed by the Tab key into the active window.
To make it loop, add a “Loop” action between the “Focus on text field in window” and “Send keys” actions in the flow. In the “Loop” dialogue box, set the “Start from” as 1, the “End to” as 10, and increment as 1. The flow should look like the second image below.
Running the flow, will focus the text field to “Other” and fill all the fields with “Test”.
Power Automate Tip #16: Run python script to validate email address format
First, set a variable as “EmailAddress”.
Then, write a python script to create regex and method to check email and validate if it’s valid or invalid.
Clicking on the flow variable pane, will show the python script output and if the email is valid or invalid.
Power Automate Tip #17: Run desktop flow
Assuming the validate email script we discussed in Tip #16 is on a separate desktop flow, we can call the desktop flow by searching for the “Run desktop flow” action. Choose “Validate Email Address” from the Desktop flow dropdown menu. Declare the input variable as the email address whose validity you want to check.
Running the flow, will allow you to run the python script and show if the email address is valid or invalid in the flow variables pane.
Power Automate Tip #18: Run JavaScript function on webpage
Microsoft Power Automate does not have a scroll down action to allow scrolling on a webpage. Fortunately, you can use the “Run JavaScript function on webpage” to do so!
In the “Run JavaScript function on webpage” dialogue box, under “JavaScript function”, indicate the function – “ExecuteScript” and declare the class name.
In order to get the class name, open your web browser, focus on the portion of the webpage beyond which you want to scroll, and right-click on it. From the dropdown menu, choose “Inspect”. In this case, we wish to scroll past the “Get started” button, hence we right-click on it and select “Inspect”. Doing this will reveal the class name.
You can then copy the class name and paste it in the “Run JavaScript function on webpage” dialogue box. Then we get the value of x with an index of zero – “x[0].scrollintoView();”
Running the flow will open the webpage and scroll to the desired portion of it!
Power Automate Tip #19: Extract data from webpage
Let’s assume we wanted to extract the Amount and Change for Euro from the webpage.
Start by selecting the “Extract data from webpage” action, and then select the browser instance you want to extract the data from. An Extraction preview popup will appear.
In order to extract the data, right-click and select “Extract element value” from the dropdown menu, and then click on text(‘Euro’). Repeat these steps for “Amount” and “Change(24h)”. You will notice the Extraction preview popup will begin to fill up with values.
Upon selecting the next row – British Pound, you will automatically populate the rest of the rows.
You can then rename your columns. In this case, the column names will be “Currency”, “Amount”, “Change(24h)”.
After running the flow, open the “DataFromWebPage” variable value from the flow variables column. You have successfully extracted data from a webpage!
Power Automate Tip #20: Manage errors
Let’s say we’re using on block error to manage what happens when the flow encounters an error, and we would like to capture the reason for the error(s). To capture the error message of any error within a block of actions, use the “Get last error” action.
First, select the “on-block error” action from the action pane. In the on block error dialogue box, give it a name. Then click on “Continue flow run”, and select “go to end of block”, and click Save.
Select the actions that you would like to manage with the on block error action and put them within the on block error action (pink section).
Select the “get last error” action and drag it below the on block error action.
In our example, to simulate an error, we wrote a flow to extract data from webpage, but closed the browser before extraction could begin (prompted by a display message box). With the “get last error” action, we will be able to see the error message “click link on webpage failed” in the LastError variable (in the variable pane).
More Power Automate tips & tricks coming your way!
We hope you found these tips useful! Did you miss part 1? Check out 30 Power Automate Tips & Tricks (Part 1)!
Meanwhile, keep a lookout for Part 3 for even more tips and tricks!