Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99419

Automating Chrome WebDriver - Select Date from DatePicker using PowerShell and Selenium

$
0
0

Many thanks to:
https://tech.mavericksevmont.com/blog/powershell-selenium-automate-web-browser-interactions-part-i/https://tech.mavericksevmont.com/blog/powershell-selenium-automate-web-browser-interactions-part-ii/https://tech.mavericksevmont.com/blog/powershell-selenium-automate-web-browser-interactions-part-iii/ for aspiring me to automate Chrome to perform a redundant task that I perform everyday.

I wish that I could select a date instead of sending keys to a datepicker using Selenium in PowerShell.

As per this weblink this is how they do it using Python. The task is very simple and PowerShell is bloat-free when it comes to dependencies.

Here is the story with all sorts of error which I am unable to solve:

$URL = "https://jqueryui.com/datepicker/"

[OpenQA.Selenium.Chrome.ChromeOptions]$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.PageLoadStrategy = "eager"
$ChromeOptions.addArguments('start-maximized')
$ChromeDriver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" -ArgumentList @($ChromeOptions)

$ChromeDriver.Navigate().GoToURL($URL)

$Frame = 0
$SelectFrame = $ChromeDriver.SwitchTo().Frame($Frame)

$SelectFrame.FindElementByXPath("//*[@id='datepicker']").click()

$SelectDate = "15"
$dateWidget = $ChromeDriver.FindElementById("ui-datepicker-div")
$cols = $dateWidget.FindElementByTagName("td")

foreach ($cells in $cols) {
    $date = $cells.getText() 
    if($date -eq $SelectDate) {
        $cells.FindElementByLinkTest($date).click()
        break
    }
}

Pause
Function Stop-ChromeDriver {Get-Process -Name chromedriver -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue}
$ChromeDriver.Close()
$ChromeDriver.Quit()
Stop-ChromeDriver

Would it be possible using PowerShell too?

Many thanks


Viewing all articles
Browse latest Browse all 99419

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>