Using Selenium in PowerShell, cannot capture dropdown

Welcome Forums General PowerShell Q&A Using Selenium in PowerShell, cannot capture dropdown

Viewing 0 reply threads
  • Author
    Posts
    • #191755
      Participant
      Topics: 28
      Replies: 28
      Points: 163
      Rank: Participant
      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 = FindSeElement Driver $chrome Timeout 30 XPath "//span[@id='control-wrapper-mainForm-GroupBoxDesignerControl4']//tr[1]//td[2]"`
      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 = FindSeElement Driver $chrome Timeout 30 XPath "//span[@id='control-wrapper-mainForm-GroupBoxDesignerControl4']//tr[1]//td[2]"
      $Value
      = 'Joe Smith'
      $SelectElement
      = [OpenQA.Selenium.Support.UI.SelectElement]::new($User)
      $SelectElement
      .SelectByValue($Value)`

      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[4]"
      [System.Windows.Forms.SendKeys]::SendWait('hosting');

      And it works, but not if I were to try and run this as a scheduled task due to the Windows SendKeys call

Viewing 0 reply threads
  • You must be logged in to reply to this topic.