Powershell, ie9 and getElementById

匿名 (未验证) 提交于 2019-12-03 01:29:01

问题:

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:

    Benutzername:                       Passwort:                       

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 

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

回答1:

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.



回答2:

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

"



回答3:

Example of using querySelector:

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!