One of the most useful benefits of learning a scripting language like PowerShell is the ability to automate tasks. There are some tasks that we do regularly. It is useful to automate such repetitive tasks and actions.
A browser is a software that we use regularly. More often than not we end up browsing the same website again. And also sometimes we perform the same activity on the websites.
Our life becomes much easier if we automate the process using PowerShell scripts. In this article, we will see step by step instructions on how to automate website search in Google Chrome using PowerShell.
Setting up Selenium:
For achieving Chrome browser automation we need to use a dll called Selenium. Alongside the dll we also need a chromedriver.exe. Follow the below steps to see how to download and set up the necessary files for Chrome automation.
- Go to selenium website using the below link.
- Click on the download button shown in the image.
- Extract the RAR file.
- Right-click the file and select rename.
- Rename the file with the .zip extension.
- Right-click the file and select extract files.
- Come to the location shown in the image.
- Copy the DLL and place it in the destination folder.
- Use the below link to download the Chrome driver.
- Download the driver that is appropriate to the Chrome version.
- You can check the Chrome version using the link given below.
- Extract Chrome driver zip file.
- Copy the chromedriver.exe to the same destination folder.
- Once done we will have the necessary dll and the chromedriver.exe in our destination folder as shown in the image.
PowerShell browser automation scripts:
- Import the dll file using the full path of the dll file.
- Create an instance of Chrome using the below script.
- We can see the automated test software.
- Navigate to the desired website using this script.
- Right-click and select inspect element.
- Scroll down the page to right click on the search box and select inspect element.
- Right click the element in the developer tools and click copy path select copy X path.
- Enter script with the copied path and the search term as shown in the image.
- We can see that the search term has entered into the search box as expected.
- Enter the below script rail press the enter key.
- We can see that it has carried out the search for the term PowerShell.
We have automated the process of using the Chrome browser in PowerShell for the mentioned task.
In this article, we learn how to set up selenium and chromedriver.exe file to use PowerShell and automate the Chrome browser. We have given step by step instructions on how to use PowerShell to automate the Chrome browser.
If you have any doubts please ask us in the comments below.
Grab the latest information related to PowerShell, Microsoft Teams, and other technologies at TecKangaroo.