這是一個觸發Internet Explorer的PowerShell腳本,打開LinkedIn登錄頁面並在用戶名文本字段中輸入一些文本。如何通過Power Shell將文本輸入到輸入字段中?
$ie = New-Object -Com "InternetExplorer.Application"
$ie.Navigate("www.linkedIn.com")
$ie.Visible = $true
$doc = $ie.document
$usernameElement = $doc.getElementByTagName("input") | Where-Object {$_.id = "session_key-login""}
$usernameElement.Click()
Get-Process iexplore | Foreach-Object {$_.CloseMainWindow()}
不幸的是,我不斷收到以下錯誤:
You cannot call a method on a null-valued expression.
At C:\Users\Pinku\Desktop\Untitled1.ps1:7 char:23
+ $usernameElement.Click <<<<()
+ CategoryInfo : InvalidOperation: (Click:String) [], RuntimeExcepti
on
+ FullyQualifiedErrorId : InvokeMethodOnNull
我都試過,但一直無法從這個issue.Please建議減輕嘍!
嗨,感謝您的回覆,但我已經嘗試過您的解決方案。我仍然得到同樣的錯誤。 –
請參閱上述編輯以獲取其他疑難解答步驟 – HAL9256
我收到此貼子您的建議 - '您無法在空值表達式上調用方法。 在C:\ Users \ Pinku \ Desktop \ Untitled1.ps1:6 char:45 + $ usernameElement = $ doc.getElementsByTagName <<<<(「Input」)|選擇ID,名稱 + CategoryInfo:InvalidOperation:(getElementsByTagName:String)[],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull 您無法在空值表達式上調用方法。 在C:\用戶\產品庫\桌面\ Untitled1.ps1:7字符:23 + $ usernameElement.Click <<<<() + CategoryInfo:InvalidOperation:(點擊:字符串)[],的RuntimeException + FullyQualifiedErrorId: InvokeMethodOnNull' –