InternetExplorer.Application:选择多个“选项值”字段

时间:2010-02-09 10:40:46

标签: internet-explorer powershell

使用Powershell尝试使用IE Automation。 任务:选择多个选项值字段,然后单击“提交”按钮。

HTML看起来像:

:
:
:
<center><input type="hidden" name="HF_certType" value="x509"><select name="HF_rvk" size="8" multiple>
<option selected value = "Line 1">Line 1 Option</option>
<option value = "Line 2">Line 2 Option</option>
<option value = "Line 3">Line 3 Option</option>
</select></center>

<p><br>
<table BORDER=0 WIDTH="100%" >
<tr>
<td WIDTH="33%"></td>

<td WIDTH="33%"><input type="submit" value="Submit" name="btn_Submit" tabindex="2"></td>

:
:
:

所以:

$ie=New-Object -comobject InternetExplorer.Application  
$ie.visible=$true 
$ie.Navigate("https://test.com/test.exe")
$ie.Document.getElementById("btn_Submit").Click() 

选择第1行是因为它是默认值。

如何选择所有行?

如何选择第2行?

1 个答案:

答案 0 :(得分:0)

想想我自己找到答案,除非有人有更好的方法:

($ie.document.getElementsByTagName("option") | where {$_.innerText -like "*Line 3*"}).IHTMLOptionElement_selected = $True