0

有人可以在PowerShell知道爲什麼我不能找到用戶名輸入字段使用其ID「user_name」?我曾在其他網站上嘗試過這方面的內容,但它一直在努力,但對於這一點,它只是拒絕找到它。我也嘗試了IHTMLDocument3_getElementsByName方法和IHTMLDocument3_getElementsByTagName尋找諸如「輸入」甚至「div」之類的東西。一些div類彈出,但有很多錯過了,我不知道爲什麼它失蹤。請給我看看燈光。Powershell IE登錄自動化無法找到元素ID

#ID names 
$IDuserName = "user_name" 
$IDuserPass = "user_password" 

$url = "https://isssupport.service-now.com/" 
$ie = New-Object -com InternetExplorer.Application 
$ie.visible = $true 
$ie.navigate($URL) 

While ($IE.Busy -eq $true) {Start-Sleep -Milliseconds 1000} 

$ie.Document.IHTMLDocument3_getElementByID($IDuserName).Value = $userName 

下面是用戶名輸入字段

<input name="user_name" id="user_name" type="text" class="form-control" value="" autocomplete="off"> 
+0

'$ ie.Document.getElementByID($ IDuserName).value的= $ userName'通常爲我工作。 –

回答

0

頁面是內置的JavaScript加載HTML線。如果您嘗試在瀏覽器中未啓用JavaScript的情況下打開該頁面,則甚至不會看到登錄表單。這似乎是IE/PowerShell找到表單及其元素的問題。

但是你所帶來的Internet Explorer窗口到前臺,並使用Systems.Windows.Forms這樣的頁面交互:

#ID names 
$IDuserName = "user_name" 
$IDuserPass = "user_password" 

$url = "https://isssupport.service-now.com/" 
$ie = New-Object -com InternetExplorer.Application 
$ie.visible = $true 

$wshell = New-Object -ComObject wscript.shell; 
$wshell.AppActivate($ie.Name) 
Start-Sleep -Milliseconds 500 

$ie.navigate($url) 

While ($ie.Busy -eq $true) {Start-Sleep -Milliseconds 1000} 

Add-Type -AssemblyName System.Windows.Forms 
[System.Windows.Forms.SendKeys]::SendWait('username'); 
[System.Windows.Forms.SendKeys]::SendWait('{TAB}'); 
[System.Windows.Forms.SendKeys]::SendWait('password'); 
[System.Windows.Forms.SendKeys]::SendWait('{ENTER}'); 

請問你正在構建腳本的目的是什麼?

問候

岡瑟

+0

感謝Guenther的這些信息,它會讓我永遠找到答案。我最近剛剛加入公司,並被委派自動化一些服務檯任務,所以我只是想找出最好的語言來自動化它。似乎Powershell可能不是這項任務最簡單的語言。 –

+0

嗨邁克爾,如果你認爲你的問題得到解答,請將其標記爲這樣。此外,如果你進入自動化,我可以推薦[sikulix](http://www.sikulix.com) – gpunktschmitz