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

How to Select Current Work Shift from a Drop Down List - PowerShell / Selenium / Chrome

$
0
0

I'm trying to automate some data entry into a Chrome Browser.

One field in particular that I'd like to automate the selection of, is a Work Shift drop down list. This list displays a list of today's shifts for a machine. It's only today's shifts, so there can't be any more than 3 options in the list.

Prior to selecting the shift, you must select the Machine, and then the date - and those 2 things determine which options you see available in the Shift field.

'''
    $MyURL = "http://servername/login" #declaring the site I want to start at
    $Today = (Get-Date).ToString('d') 
    $Now = (Get-Date).ToString('t')
    $env:COMPUTERNAME #referencing computername for later
    $Env:Path += ";C:\temp\PS-SELENIUM\Selenium" 
    Add-Type -Path "C:\temp\PS-SELENIUM\Selenium\WebDriver.Dll"
    Add-Type -Path "c:\temp\PS-SELENIUM\Selenium\WebDriver.Support.Dll"
    $ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
    $ChromeDriver.Navigate().GoToURL($MyURL)
    $ChromeDriver.FindElementbyName("User").SendKeys("plant")
    $ChromeDriver.FindElementbyName("password").SendKeys("plant")
    $ChromeDriver.FindElementbyName("submit").Submit()
    $ChromeDriver.Navigate().GoToURL("http://servername/machinepage") 
    $ChromeDriver.FindElementbyName("STATIONLINK").SendKeys("202") #assigning a machineID 
    $ChromeDriver.FindElementByName("SELECTEDDATE").SendKeys("$Today") #inputting the date 

----Here is where I think I want to insert some code to analyze which shifts are available from selection, and to then evaluate which shift overlaps with the current time, in order to determine whether to feed the field a 1,2 or 3 (in this case).------

----Below is the webpage info that houses the shift info once the machine and date have been selected.

<select id="SHIFTLINK" name="SHIFTLINK" onchange="SelectedShift(this);" required="" style="" 
    xpath="1">
            <option value=""></option>
            <option value="285426">1 [2/20/2020 6:00:00 AM - 2/20/2020 2:30:00 PM]</option>
            <option value="285427">2 [2/20/2020 2:30:00 PM - 2/20/2020 11:00:00 PM]</option>
            <option value="285428">3 [2/20/2020 11:00:00 PM - 2/21/2020 6:00:00 AM]</option>
        </select>



$ChromeDriver.FindElementByName("SHIFTLINK").SendKeys('2')
$ChromeDriver.FindElementByName("SHIFTLINK").SendKeys('2') #intentional
$ChromeDriver.FindElementByID("Submit").Submit()

I've read online that I may need to be using a Select function/statement to call these values. I've tried a List option - but I get a "term not recognized as the name of a cmdlet" error. Here's the specific line that doesn't work for me:

List<WebElement> options = $ChromeDriver.FindElementsbyname("SHIFTLINK") #- doesn't work because List<WebElement> is not recognized

Viewing all articles
Browse latest Browse all 98494

Latest Images

Trending Articles



Latest Images

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