从下拉菜单中选择选项 [英] Select option from dropdown
本文介绍了从下拉菜单中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一些自动化工作,遇到了一个下拉菜单,选择一个选项时遇到了问题.
I'm working on some automation and I came across one dropdown where I'm having an issue to select an option.
只有这样,我才能使元素处于IHTMLDocument3
谷底:
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?
推荐答案
枚举选项,按其值(或内部文本)过滤要选择的选项,然后选择它:
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 }
这篇关于从下拉菜单中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文