2010-02-09 167 views
2

使用Powershell尝试IE自动化。 任务:选择多个选项值字段并单击提交按钮。InternetExplorer.Application:选择多个“选项值”字段

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> 

: 
: 
: 

所以:1

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

线路选择,因为它的默认值。

如何选择所有行?

我该如何选择第2行?

回答

0

想我找到了自己的答案,除非某人有一个更好的办法:

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