This is the code:
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
$username="[email protected]"
$password="MyPassword"
$ie.Navigate("https://service.post.ch/zopa/dlc/app/?service=dlc-web&inMobileApp=false&inIframe=false&lang=fr#!/main")
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}
$usernamefield = $ie.document.getElementByID('isiwebuserid')
$usernamefield.value = "$username"
$passwordfield = $ie.document.getElementByID('isiwebpasswd')
$passwordfield.value = "$password"
$Link = $ie.document.getElementByID('actionLogin')
$Link.click()
while($ieobject.Busy) { Start-Sleep -seconds 10 }
$ie.Quit()
As you can see from the video the website post.ch opens up but then the window closes even if I set Start-Sleep -seconds 10
before $ie.Quit()
This makes me think that probably the script is working but not sure what happens in the next page.
The browser just closes.
Any idea what's going on?
You can also create an account on that website if you wan to test.
The error says:
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:12 char:1
+ $usernamefield = $ie.document.getElementByID('isiwebuserid')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:13 char:1
+ $usernamefield.value = "$username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:15 char:1
+ $passwordfield = $ie.document.getElementByID('isiwebpasswd')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:16 char:1
+ $passwordfield.value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:18 char:1
+ $Link = $ie.document.getElementByID('actionLogin')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
You cannot call a method on a null-valued expression.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:19 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
While ($ie.Busy -eq $true)
is not a valid way to wait until a website is loaded. Unfortunately, there is no standard way of telling that a website is fully loaded. Javascript could load things at any time later, or permanently.
So you have to define your "fully loaded" state by yourself. For example, you could wait until a certain element exists.
Besides that, it looks like the website doesn't load in IE at all. So the elements will never be available in this browser (at least on my machine). It works in Edge and Firefox, though.
If the website loads in your IE, you can replace While ($ie.Busy -eq $true) ...
, by just Start-Sleep -Seconds 10
. So that you definitely wait 10 s. This should be enough for the elements to load (if they do it at all). And the errors should be gone. If that works, look for a better method to wait.