I have been attempting to automate a web page (help desk form) in PowerShell with the Selenium module. I can get all different types of elements except dropdowns. I have inconsistently been able to get some of them by doing a Find-SEElement and using the -xPath, performing a click() and then doing a Find-SEElement again on the resultant drop down list, but this does not
always work. The one I am working on at the moment looks like this:
`$User = Find-SeElement -Driver $chrome -Timeout 30 -XPath "//span[@id='control-wrapper-mainForm-GroupBoxDesignerControl4']//tr//td"`
I can confirm that I do find the element, but if I try to do anything except click on it I get the "element is not interactable" error. I was reading through some other forums, and someone suggested doing something like this:
`$User = Find-SeElement -Driver $chrome -Timeout 30 -XPath "//span[@id='control-wrapper-mainForm-GroupBoxDesignerControl4']//tr//td"
$Value = 'Joe Smith'
$SelectElement = [OpenQA.Selenium.Support.UI.SelectElement]::new($User)
When I run this, however, I get the error “Element should have been select but was td”. Googling this I have seen a number of threads and solutions for other languages such as Python and C#, but nothing specific to PowerShell. I am just looking for a consistent syntax to be able to grab a dropdown menu and select an item from the resultant list.
Edit: I did realize that the element is a /td, not a select, after posting, based on the XPath. The question remains, however, how to consistently grab the dropdown menu and then select a value. I have done it like this (different element name but shows same issue):
$taskLink = Find-SeElement -Driver $chrome -Timeout 30 -Wait -XPath “//li[contains(text(),‘Add Task’)]”
Invoke-SeClick -Element $taskLink -Driver $chrome
$taskDropdown = Find-SeElement -Driver $chrome -Timeout 60 -XPath “//div[@id=‘mainForm-_SupportGroup-Dropdown’]//div”
And it works, but not if I were to try and run this as a scheduled task due to the Windows SendKeys call