2011-05-19 47 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")