Hi,
When trying to run a script to login to site using credentials, I get an error message saying
"You cannot call a method on a null-valued expression.
At line:11 char:28
+ $ie.document.getElementById <<<< ("strUserID").value= "$username"
+ CategoryInfo : InvalidOperation: (getElementById:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull".
The script that I used is:
$username = "acd"
$password = "acd"
$servername = "acd"
$url = "www.somewebsite.com"
$EmailSubject = "acd"
$BodyText = "acd"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("$url")
#while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("strUserID").value= "$username"
$ie.document.getElementById("strPassword").value = "$password"
$ie.document.getElementById("$btnLogon").click()
$content = $ie.Document.body.innertext | Out-String
In the source code, I found that the username and password component is not addressed by an ID, it is addressed by Name. I tried using "getElementByname" as well but the same error message was displayed. The source code part that contains the username component is as below for your reference so that you could get an idea of where I am missing:
<TDalign="right"><FONTcolor="#000000"face="Verdana"size="1">Username: </FONT></TD>
<TDalign="right"><P><INPUTtype="text"name="strUserID"size="30"value=""></P></TD>
Please suggest a solution or put light on where I am going wrong. Thanks in advance for any help.