Powershell, ie9 and getElementById
Asked Answered
B

3

5

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

Beget answered 19/5, 2011 at 22:4 Comment(0)
M
2

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.

Mallette answered 20/5, 2011 at 5:38 Comment(2)
Cool, thanks that helped. I added the site to the list of websites for compatibility viewBeget
For IE11 on Server 2012 R2 This did not work, for me. I found this solution to work. However form my experience, you have to do this for each page you touch.Kindly
N
3

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

"

Neoplatonism answered 6/11, 2014 at 0:11 Comment(0)
M
2

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.

Mallette answered 20/5, 2011 at 5:38 Comment(2)
Cool, thanks that helped. I added the site to the list of websites for compatibility viewBeget
For IE11 on Server 2012 R2 This did not work, for me. I found this solution to work. However form my experience, you have to do this for each page you touch.Kindly
C
0

Example of using querySelector:

  $element = [System.__ComObject].InvokeMember("querySelector",[System.Reflection.BindingFlags]::InvokeMethod, $null, $ie.Document, "$QueryHere")
Collinsworth answered 5/2, 2016 at 10:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.