PowerShell Internet Explorer Com对象选择类下拉菜单项

时间:2015-11-06 03:11:04

标签: internet-explorer powershell

我正在尝试从下面的HTML下拉菜单中选择一个项目。

<select class="select" name="expiration">
<option value="N" selected="selected">Never</option>
<option value="10M">10 Minutes</option>
<option value="1H">1 Hour</option>
<option value="1D">1 Day</option>
<option value="1W">1 Week</option>
<option value="2W">2 Weeks</option>
<option value="1M">1 Month</option>

这是我目前的代码。我没有收到任何错误,只是项目没有被选中。

# Code to select menu item
$ie = New-Object -comobject InternetExplorer.Application 
$ie.visible = $False

# navigate to URL
$ie.navigate('http://URL')
while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 1000; }

$expiration = $ie.Document.getElementsByClassName('expiration')
$expiration.outerText |Select-Object -Index 2
$ie.Document.getElementById('submit').Click()
Start-Sleep -Milliseconds 1000
$result = $ie.LocationURL

1 个答案:

答案 0 :(得分:1)

试试这个:

$ie = New-Object -ComObject InternetExplorer.Application 
$ie.Visible = $False
$ie.navigate("http://URL")
while ($ie.Busy) { Start-Sleep -Milliseconds 1000 }

$expiration = $ie.Document.getElementsByClassName("select")
$expiration.Options.SelectedIndex = 2
$ie.Document.getElementById("submit").Click()
Start-Sleep -Milliseconds 1000
$result = $ie.LocationURL