activities
latest
false
- Overview
- UI Automation
- Applications and technologies automated with UI Automation
- Project compatibility
- UI-ANA-016 - Pull Open Browser URL
- UI-ANA-017 - ContinueOnError True
- UI-ANA-018 - List OCR/Image Activities
- UI-DBP-006 - Container Usage
- UI-DBP-013 - Excel Automation Misuse
- UI-DBP-030 - Forbidden Variables Usage In Selectors
- UI-PRR-001 - Simulate Click
- UI-PRR-002 - Simulate Type
- UI-PRR-003 - Open Application Misuse
- UI-PRR-004 - Hardcoded Delays
- UI-REL-001 - Large Idx in Selectors
- UI-SEC-004 - Selector Email Data
- UI-SEC-010 - App/Url Restrictions
- UI-USG-011 - Non Allowed Attributes
- UX-SEC-010 - App/Url Restrictions
- UX-DBP-029 - Insecure Password Use
- UI-PST-001 - Audit Log Level in Project Settings
- UiPath Browser Migration Tool
- Clipping region
- Computer Vision Recorder
- Activate
- Anchor Base
- Attach Browser
- Attach Window
- Block User Input
- Callout
- Check
- Click
- Click Image
- Click Image Trigger
- Click OCR Text
- Click Text
- Click Trigger
- Close Application
- Close Tab
- Close Window
- Context Aware Anchor
- Copy Selected Text
- Element Attribute Change Trigger
- Element Exists
- Element Scope
- Element State Change Trigger
- Export UI Tree
- Extract Structured Data
- Find Children
- Find Element
- Find Image
- Find Image Matches
- Find OCR Text Position
- Find Relative Element
- Find Text Position
- Get Active Window
- Get Ancestor
- Get Attribute
- Get Event Info
- Get From Clipboard
- Get Full Text
- Get OCR Text
- Get Password
- Get Position
- Get Source Element
- Get Text
- Get Visible Text
- Go Back
- Go Forward
- Go Home
- Google Cloud Vision OCR
- Hide Window
- Highlight
- Hotkey Trigger
- Hover
- Hover Image
- Hover OCR Text
- Hover Text
- Image Exists
- Indicate On Screen
- Inject .NET Code
- Inject Js Script
- Invoke ActiveX Method
- Key Press Trigger
- Load Image
- Maximize Window
- Microsoft Azure Computer Vision OCR
- Microsoft OCR
- Microsoft Project Oxford Online OCR
- Minimize Window
- Monitor Events
- Mouse Trigger
- Move Window
- Navigate To
- OCR Text Exists
- On Element Appear
- On Element Vanish
- On Image Appear
- On Image Vanish
- Open Application
- Open Browser
- Refresh Browser
- Replay User Event
- Restore Window
- Save Image
- Select Item
- Select Multiple Items
- Send Hotkey
- Set Clipping Region
- Set Focus
- Set Text
- Set To Clipboard
- Set Web Attribute
- Show Window
- Start Process
- System Trigger
- Take Screenshot
- Tesseract OCR
- Text Exists
- Tooltip
- Type Into
- Type Secure Text
- Use Foreground
- Wait Attribute
- Wait Element Vanish
- Wait Image Vanish
- Application Event Trigger
- Check/Uncheck
- Check App State
- Check Element
- Click
- Click Event Trigger
- Close Popup
- Drag and Drop
- Extract Table Data
- For Each UI Element
- Get Attribute
- Get Browser Data
- Get Text
- Get URL
- Go to URL
- Highlight
- Hover
- Inject Js Script
- Keyboard Shortcuts
- Keypress Event Trigger
- Mouse Scroll
- Navigate Browser
- Select Item
- Set Browser Data
- Set Runtime Browser
- Set Text
- Take Screenshot
- Type Into
- Use Application/Browser
- Perform browser search and retrieve results using UI Automation APIs
- Web Browsing
- Find Images
- Click Images
- Trigger and Monitor Events
- Create and Override Files
- HTML Pages: Extract and Manipulate Information
- Window Manipulation
- Automated List Selection
- Find and Manipulate Window Elements
- Manage Text Automation
- Load and Process Images
- Manage Mouse Activated Actions
- Automate Application Runtime
- Automated Run of a Local Application
- Browser Navigation
- Web Automation
- Trigger Scope Example
- Computer Vision Local Server
- Mobile Automation
- Release notes
- Project compatibility
- Get Log Types
- Get Logs
- Get Page Source
- Get Device Orientation
- Get Session Identifier
- Install App
- Manage Current App
- Manage Other App
- Open DeepLink
- Open URL
- Mobile Device Connection
- Directional Swipe
- Draw Pattern
- Positional Swipe
- Press Hardware Button
- Set Device Orientation
- Take Screenshot
- Take Screenshot Part
- Element Exists
- Execute Command
- Get Attribute
- Get Selected Item
- Get Text
- Set Selected Item
- Set Text
- Swipe
- Tap
- Type Text
- Terminal
Perform browser search and retrieve results using UI Automation APIs
UI Automation Activities
Last updated Oct 28, 2024
Perform browser search and retrieve results using UI Automation APIs
This tutorial illustrates how to use UI Automation APIs to create an automation that opens the Google search engine, performs a UiPath search, retrieves the result from the official UiPath website, and displays it in the console.
- UiPath Studio 2023.10 or higher
- UiPath.UIAutomation.Activities 23.10.3 or higher
- Visit Using objects in coded automations and learn the methods you can employ for using object repository elements within your coded automation.
- Create a coded workflow by selecting New, and then Coded Workflow from the File group.
- Capture all the UI elements that you want to use in your coded workflow inside
the Object Repository.
For this example you need to capture the following UI elements:
GoogleHomeScreen
- the Google home screen, where you perform the search.googleSearchBar
- the Google search bar where you type the UiPath keyword.
googleResultsScreen
- the screen that shows the first Google results after performing the search.firstPageOfResults
- the part of the screen that includes only the first results.uipathOfficialWebsite
- the result that takes you to the UiPath official website.
- Create a variable for the Google home screen and open it using the Open API.
public class Search : CodedWorkflow { [Workflow] public void Execute() { // 1. Open Google var homeScreen = uiAutomation.Open(ObjectRepository.Descriptors.Google.GoogleHomeScreen);
public class Search : CodedWorkflow { [Workflow] public void Execute() { // 1. Open Google var homeScreen = uiAutomation.Open(ObjectRepository.Descriptors.Google.GoogleHomeScreen); - Type UiPath in the Google search bar, using the TypeInto API.
// 2. Type "UiPath" in the Google search bar homeScreen.TypeInto(ObjectRepository.Descriptors.Google.GoogleHomeScreen.googleSearchBar, "UiPath");
// 2. Type "UiPath" in the Google search bar homeScreen.TypeInto(ObjectRepository.Descriptors.Google.GoogleHomeScreen.googleSearchBar, "UiPath"); - Send the Enter keyboard shortcut to search for the corresponding result,
using the KeyboardShortcut API.
// 3. Send the "Enter" keyboard shortcut to search for the corresponding Google results homeScreen.KeyboardShortcut(ObjectRepository.Descriptors.Google.GoogleHomeScreen.googleSearchBar, "[d(hk)][k(enter)][u(hk)]");
// 3. Send the "Enter" keyboard shortcut to search for the corresponding Google results homeScreen.KeyboardShortcut(ObjectRepository.Descriptors.Google.GoogleHomeScreen.googleSearchBar, "[d(hk)][k(enter)][u(hk)]"); - Focus on the screen with the
Google results, using the Attach API.
Note: You use the Attach API over the Open API when you need to target a specific screen within an application that has already been opened using the Open API. The Attach API prevents unnecessary application launches, ensuring your automation stays on track.
var googleScreen = uiAutomation.Attach(ObjectRepository.Descriptors.Google.googleResultsScreen);
var googleScreen = uiAutomation.Attach(ObjectRepository.Descriptors.Google.googleResultsScreen); - Get the text from the first Google results and print it out in the console,
using the GetText API.
string firstresultsText = googleScreen.GetText(ObjectRepository.Descriptors.Google.googleResultsScreen.firstPageOfResults); Console.WriteLine(firstresultsText);
string firstresultsText = googleScreen.GetText(ObjectRepository.Descriptors.Google.googleResultsScreen.firstPageOfResults); Console.WriteLine(firstresultsText); - Create an If clause that prints out the the text of the first result that
contains the
"https://www.uipath.com"
string within it.// Initialize with an empty string string officialWebsiteUiPath = ""; if (firstresultsText.Contains("https://www.uipath.com")) { officialWebsiteUiPath = googleScreen.GetText(ObjectRepository.Descriptors.Google.googleResultsScreen.uipathOfficialWebsite); } Console.WriteLine(officialWebsiteUiPath);
// Initialize with an empty string string officialWebsiteUiPath = ""; if (firstresultsText.Contains("https://www.uipath.com")) { officialWebsiteUiPath = googleScreen.GetText(ObjectRepository.Descriptors.Google.googleResultsScreen.uipathOfficialWebsite); } Console.WriteLine(officialWebsiteUiPath);
The automation opens the Google search engine in your preferred web browser, performs
a search for UiPath, retrieves the results from the initial page, and
extracts the text from the result that contains the following link:
https://uipath.com
.
To follow the steps of this tutorial and try it out yourself, you can download the following sample project: Goggle Results using UI Automation APIs.