Powershell、ie9 和 getElementById

发布于 2024-11-09 01:55:43 字数 1800 浏览 3 评论 0原文

我成功地使用此网站的 Web 自动化脚本: heise Web 自动化

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

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 发生了变化。

有人可以帮忙吗?

谢谢,大卫

I use successfully a script for web automation from this site: heise web automation

I know it is in german, but perhaps someone can help.

The important part of the e-plus website:

    <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>

the part of the Powershell script:

$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()
    }
}

the getElementById worked for ie8 but now I have updated to ie9 and it is not working anymore.

the errormessage:

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

the count of the arguments is wrong.

all I was able to find was a hint, that in ie9 getElementById changed.

can anybody help?

Thanks, David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无言温柔 2024-11-16 01:55:43

请参阅http://www.experts-exchange.com/Web_Development/Web_Languages-标准/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))

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

Quoted:
"I should've used member invocation:

$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)

and for getElementsByTagName:

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

"

青萝楚歌 2024-11-16 01:55:43

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

When automating only one concrete site (and the script is not generic or any site) you can try to set compatibility view in IE settings (Tools -> Compatibility View settings). IE should switch to IE8 view when browsing the site.

靑春怀旧 2024-11-16 01:55:43

使用查询选择器的示例:

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

Example of using querySelector:

  $element = [System.__ComObject].InvokeMember("querySelector",[System.Reflection.BindingFlags]::InvokeMethod, $null, $ie.Document, "$QueryHere")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文