2011-05-19 32 views
4

我成功地使用了網絡自動化的腳本從這個網站:heise web automationPowerShell中,IE9和的getElementById

我知道這是在德國,但也許有人可以提供幫助。

電子加網的重要組成部分:

<tr> 
     <td class="td1">Benutzername:</td> 
     <td class="space"><img src="/img/c.gif" alt="" /></td> 
     <td class="td2"><input type="text" id="IDToken1OL" name="IDToken1" onfocus="setToken(this)" onblur="getToken(this)" value="Benutzername" /></td> 
    </tr> 
    <tr> 
     <td class="td1">Passwort:</td> 
     <td class="space"><img src="/img/c.gif" alt="" /></td> 
     <td class="td2"><input type="password" id="IDToken2OL" name="IDToken2" onfocus="setToken(this)" onblur="getToken(this)" value="" class="passwortFake" /></td> 
    </tr> 

PowerShell腳本的一部分:

$script:ie = New-Object -comobject InternetExplorer.Application 
$ie.visible = $false 
$ie.silent = $true 
# 
$ie.Navigate("https://www.eplus.de/login/login.asp") 
LadenWarten(1) 
# 
$ie.Document.getElementById("IDToken1OL").value = $user 
$ie.Document.getElementById("IDToken2OL").value = $passwort 
$ie.Document.getElementsByTagName("a") | foreach { 
    if ($_.href -eq "javascript:SSO_Submit()") { 
     $_.Click() 
    } 
} 

中的getElementById工作了IE8,但我現在已經更新到IE9,這是不再工作了。

的errormessage的:

+ $ie.Document.getElementById <<<< ("IDToken1OL").value = $user 
    + CategoryInfo   : NotSpecified: (:) [], ParentContainsErrorRecordException 
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest 

的參數的數量是錯誤的。

我所能找到的只是一個提示,即在ie9中getElementById發生了變化。

任何人都可以幫忙嗎?

謝謝,大衛

回答

2

當自動化只有一個具體的網站(和腳本不是一般的或任何網站),你可以嘗試設置在IE設置兼容性視圖(工具 - >兼容性視圖設置)。瀏覽網站時IE應切換到IE8視圖。

+0

很酷,謝謝你的幫助。我將該網站添加到兼容性視圖的網站列表中 – David 2011-05-20 16:43:09

2

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Q_27920160.html -

報價: 「我用過成員調用:

$ie = new-object -com "InternetExplorer.Application" 
$ie.navigate("about:blank") 
$doc = $ie.Document 

$element = [System.__ComObject].InvokeMember(「getElementById」,[System.Reflection.BindingFlags]::InvokeMethod, $null, $doc, $id) 

和的getElementsByTagName:

$elements = @([System.__ComObject].InvokeMember(「getElementsByTagName」,[System.Reflection.BindingFlags]::InvokeMethod, $null, $doc, $tagname)) 

」 使用

0

例querySelector:

$element = [System.__ComObject].InvokeMember("querySelector",[System.Reflection.BindingFlags]::InvokeMethod, $null, $ie.Document, "$QueryHere")