這是代碼:
$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()
正如您從視頻中看到的那樣,網站 post.ch 會打開,但即使我之前設定Start-Sleep -seconds 10過,視窗也會關閉$ie.Quit()
這讓我認為腳本可能正在運行,但不確定下一頁會發生什么。

瀏覽器剛剛關閉。
知道發生了什么嗎?
如果您想進行測驗,您也可以在該網站上創建一個帳戶。
錯誤說:
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
uj5u.com熱心網友回復:
While ($ie.Busy -eq $true)不是等待網站加載的有效方法。不幸的是,沒有標準的方式來判斷網站是否已滿載。Javascript 可以在以后的任何時間或永久加載東西。
所以你必須自己定義你的“滿載”狀態。例如,您可以等到某個元素存在。
除此之外,看起來該網站根本無法在 IE 中加載。所以這些元素在這個瀏覽器中永遠不可用(至少在我的機器上)。不過,它適用于 Edge 和 Firefox。
如果網站在您的 IE 中加載,您可以將While ($ie.Busy -eq $true) ...,替換為Start-Sleep -Seconds 10. 這樣你肯定要等 10 秒。這應該足以加載元素(如果他們這樣做的話)。并且錯誤應該消失了。如果可行,請尋找更好的等待方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/419303.html
標籤:
