When it comes to automating browser-based tasks, two of the most popular tools in the market are Selenium and Power Automate RPA. While both of them have their own advantages, the choice between the two primarily depends on the specific use case.
Selenium is an open-source tool used for automating web applications for testing purposes, but it is also used for repetitive web-based administration tasks. Power Automate RPA, on the other hand, is a solution by Microsoft that allows end-to-end automation of tasks, involving multiple applications and data sources. While Power Automate RPA’s capabilities are vast, its power could be an overkill for certain situations.
The reasons to choose Selenium over Power Automate RPA are:
Cost-Effectiveness: One of the most compelling reasons to choose Selenium is that it is entirely free. On the other hand, Power Automate RPA comes with a cost that can become significant, especially for large-scale projects or for organizations with tighter budgets.
Simplicity: If your project involves simple, web-based tasks, then Selenium could be a more straightforward choice. Power Automate RPA excels in scenarios where there’s a need to integrate with multiple systems, data sources, or complex business rules. However, for basic operations such as navigating web pages, filling forms, or testing web applications, Selenium can be more than sufficient.
Customization and Flexibility: Selenium offers the ability to write scripts in various programming languages including Java, C#, Python, Ruby, etc., providing an excellent level of flexibility and customization based on the user’s programming skill and preference.
Community Support: Being open-source and widely used around the globe, Selenium has an extensive user community. This means you can easily find solutions and guidance online from developers who have faced similar issues.
First, let’s install Selenium PowerShell module.
Install-Module Selenium
in Windows PowerShell.Selenium supports multiple browsers, such as Chrome, Firefox, Edge, and Safari. Download the driver for the browser you want to use. For example, here is a Chrome driver: ChromeDriver: https://chromedriver.chromium.org/downloads At the time of writing, the current driver version was 114 (same as the Chrome or Edge version).
C:\WindowsPowerShell\Modules\Selenium\3.0.1\assemblies
. To get the exact Selenium module location, you can run this PowerShell script:Import-Module Selenium$Module = get-module Selenium$Module.Path
# Install-Module -Name Selenium # -scope CurrentUser# Import Selenium moduleImport-Module Selenium# Start Chrome browser$Driver = Start-SeChrome# Navigate to a specific URL$Driver.Navigate().GoToUrl('https://Contoso.com/Document/import/Messages.aspx')# Find the button element by ID$EmailAndPasswordRadio = $Driver.FindElementById('ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_LoginProviderRadioButtonList_1')$EmailAndPasswordRadio.Click()$SetLoginMethodButton = $Driver.FindElementById('ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_SaveLoginProviderButton')$SetLoginMethodButton.Click()# Enter login$LoginElement = $Driver.FindElementById('ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_EmailAddressTextBox')$LoginElement.SendKeys('contoso@microsoft.com')# Enter password$PasswordElement = $Driver.FindElementById('ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_PasswordTextBox')$PasswordElement.SendKeys('SamplePasswordFake')
# Click the login button$LoginButton = $Driver.FindElementById('ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_LoginButton')$LoginButton.Click()
# Read the custom JavaScript file to the page$JavaScriptCode = Get-Content -Path "..\JavaScript\Click-the-form.js" -Raw# Inject and execute the JavaScript code in the context of the current web page$Driver.ExecuteScript($JavaScriptCode)
# Close the browser window$Driver.Quit()