Select option from dropdown

2019-09-14 00:44发布

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:

This is the element I'm talking about:

Dropdown

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

1条回答
神经病院院长
2楼-- · 2019-09-14 01:46

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 }
查看更多
登录 后发表回答