2010-02-09 177 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