How to automate website actions using PowerShell

Selenium PowerShell


As you may have come across PowerShell before, there is one amazing feature I would like to introduce to you today. Not only PowerShell can manage some Windows tasks but it could handle a webpage using PowerShell program and Selenium.

Requirements:

Chrome driver from https://chromedriver.chromium.org/downloads to match your current Google Chrome's version. So mine is on v83.x then you must download the one with v83 too. Once you downloaded Chrome driver, you should replace the highlight location like screenshot showed.
















Search and Run PowerShell ISE as admin.





Now create a new script and find your cloned Selenium module for example mine saved in
C:\Users\Virtual10\Documents\GitHub\selenium-powershell
Import your Selenium.psd1 module like below scripts:

Import-Module "C:\Users\Virtual10\Documents\GitHub\selenium-powershell\Selenium.psd1"

$Driver = Start-SeChrome
if($Driver){

Enter-SeURL "https://www.techmation.xyz/2020/06/how-to-automate-website-actions-using.html" -Driver $Driver
Find-SeElement -Driver $Driver -Id 'Email' | SeType -keys "example@email.com"
Start-Sleep -Seconds 1
Find-SeElement -Driver $Driver -Id 'Password' | SeType -keys "myPassword123"
Start-Sleep -Seconds 1
$Element = Find-SeElement -Driver $Driver -Id "Remember"
Invoke-SeClick -Element $Element
Start-Sleep -Seconds 1
$Value = '2'
$Option = Find-SeElement -Driver $Driver -XPath "/html/body/div[1]/div/div/main/div/div[1]/div/div/div/div[2]/div[2]/div/select"
$SelectElement = [OpenQA.Selenium.Support.UI.SelectElement]::new($Option)
$SelectElement.SelectByValue($Value)

#$Submit = Find-SeElement -Drive $Driver -Id "submit"
#Invoke-SeClick -Element $Submit
}

Paste in the rest of the codes and press run. If everything setup correctly, you should be able to see it in action!

Thanks for reading and drop me a comment if you have any questions. 💪

Test Form

Test select options

 






Similar automation can be done with AutoHotkey program, check it out

Comments

Popular Posts