问题
I am trying to send username and password to web application from autoit script.
$oIE.document.getElementsByName($formUID).Item(0).value = $Name
$oIE.document.getElementById($formPID).value = $pwd
These functions above are working in Windows 7 but not working in Windows 8 and IE 10. Can any one help me? It's very important.
回答1:
If those fields have ID or NAME you should use
Local $oUsername = _IEGetObjById($oIE, "Username") ; _IEGetObjById or _IEGetObjByName
$oUsername.value = "myusername"
IF they dont, then you can list all elements and do a comparison on them. You can use:
$oInput.type
$oInput.Id
$oInput.name
$oInput.classname
$oInput.innerhtml
$oInput.outerhtml
$oInput.innertext
$oInput.outertext
etc...
example usage:
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
if $oInput.type == "password" then $oInput.value = "mypassword"
if $oInput.name == "username" then $oInput.value = "myusername"
Next
If it still doesn't work, try using embedded IE. If that works but you need regular IE, Consider using Compatibility mode:
$64Bit = ""
If @OSArch = "X64" Then
$64Bit = "64"
EndIf
If StringLeft(RegRead("HKLM" & $64Bit & "\SOFTWARE\Microsoft\Internet Explorer\Version Vector", "IE"), 1) > 8 Then ;Check for version 9 or later
$wshNetwork = ObjCreate("WScript.Network")
$struser = $wshNetwork.Username
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$objAccount = $objWMIService.Get('Win32_UserAccount.Name="' & $struser & '",Domain="' & @ComputerName & '"')
RegWrite("HKU" & $64Bit & "\" & $objAccount.SID & "\Software\Microsoft\Internet Explorer\BrowserEmulation\", "AllSitesCompatibilityMode", "REG_DWORD", 1)
RegWrite("HKU\" & $objAccount.SID & "\Software\Microsoft\Internet Explorer\BrowserEmulation\", "AllSitesCompatibilityMode", "REG_DWORD", 1)
EndIf
来源:https://stackoverflow.com/questions/22434470/how-to-send-to-username-and-password-to-webpage-when-it-is-not-as-form