Select option from dropdown

 ̄綄美尐妖づ 提交于 2019-12-25 09:00:30

问题


I'm working on some automation and I came across one dropdown where I'm having an issue to select an option.

Only way, I was able to get the element is trough IHTMLDocument3:

$dropdown = $ie.Document.IHTMLDocument3_getElementsByName("searchTypeChoice")

This is limiting my options how to select an option, since I can't use

.Options.Selected = $true

or anything else. I found these questions:

  • Powershell..select drop down menu from web page
  • Select option on dropdown list for web ui testing automation in windows powershell

This is the element I'm talking about:

Do you have any suggestions? Or maybe another method how to get the dropdown in other way?


回答1:


Enumerate the options, filter the one you want to select by its value (or inner text), then select it:

$dropdown.Options |
  Where-Object { $_.Value -eq 1 } |
  ForEach-Object { $_.Selected = $true }


来源:https://stackoverflow.com/questions/41482917/select-option-from-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!