【问题标题】:Powershell, ie9 and getElementByIdPowershell、ie9 和 getElementById
【发布时间】:2011-08-29 06:02:19
【问题描述】:

我成功地使用了来自该站点的网络自动化脚本:heise web automation

我知道它是德语的,但也许有人可以帮忙。

e-plus 网站的重要部分:

    <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,它不再工作了。

错误信息:

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

参数的数量是错误的。

我能找到的只是一个提示,在 ie9 中 getElementById 发生了变化。

有人可以帮忙吗?

谢谢,大卫

【问题讨论】:

    标签: powershell internet-explorer-9 getelementbyid


    【解决方案1】:

    querySelector 使用示例:

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

    【讨论】:

      【解决方案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))
      

      "

      【讨论】:

        【解决方案3】:

        当仅自动化一个具体站点(并且脚本不是通用或任何站点)时,您可以尝试在 IE 设置中设置兼容性视图(工具 -> 兼容性视图设置)。浏览网站时,IE 应切换到 IE8 视图。

        【讨论】:

        • 酷,谢谢你的帮助。我将该网站添加到网站列表中以查看兼容性
        • 对于 Server 2012 R2 上的 IE11 这对我来说不起作用。我找到this solution 工作。但是根据我的经验,您必须为您触摸的每个页面执行此操作。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-17
        • 1970-01-01
        • 1970-01-01
        • 2012-03-15
        • 2011-10-03
        • 1970-01-01
        相关资源
        最近更新 更多