Powershell使用internetexplorer.application在下拉列表中选择项目



我试图通过Powershell选择一个下拉项。它使用Javascript。到目前为止,我只实现了登录和获得一堆方法通过获取元素。见下文.

# Create an ie com object
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
# Wait for the page to load
while ($ie.Busy -eq $true){ Start-Sleep -Milliseconds 1000; }
# Login
Write-Host -ForegroundColor Green "Attempting to login.";
# Add login details
try
{
$ie.Document.IHTMLDocument3_getElementsByName("user") = $username
$ie.Document.IHTMLDocument3_getElementsByName("pass") = $password
$ie.Document.IHTMLDocument3_getElementsByName("submit")
Do{Start-Sleep -Milliseconds 100}While($ie.Busy -eq $True)    
}
catch
{
$_.Exception.Message
}
#get dropdown elementarray
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId')
#get methods
$ie.Document.IHTMLDocument3_getElementById('contentPlaceHolderId') | gm

有人知道如何在占位符中选择一个特定的元素吗?方法太多了,无法在帖子中容纳

提前感谢。

对于其他人,答案是:

($ie.Document.IHTMLDocument3_getElementById('$contentPlaceHolderId') | Where-Object { $_.innerHTML -eq '$DropDownElementName' }).selected = $true

点击按钮:

$ie.Document.IHTMLDocument3_getElementById('$button').click();