以下代码从Ie9中的html代码中获取值,但是当在Ie10 windows8中运行相同的脚本时,它不会获取Id值并填充文本框。这是我的脚本
$url = "https://190.198.14.15/"
$formID = ""
$formUID = "username"
$uName = "admin"
$formPID = "password"
$pwd = "SeR^ER@iL0"
$formSubmit = "ID_LOGON"
;Launch the Internet Explorer as a private session
ShellExecute ("iexplore.exe", " -private about:blank", @programFilesDir & "\Internet Explorer\iexplore.exe", "open", @SW_MAXIMIZE)
WinWait ("Blank Page")
$oIE = _IEAttach ("about:blank", "url")
;Wait for the IE to launch
_IELoadWait ($oIE)
;Navigate to the given URL
_IENavigate ($oIE, $url)
;Get the IE process id specific to this instance
Local $PID = WinGetProcess(_IEPropertyGet($oIE, "hwnd"))
;Print the PID in the console
If $PID Then
;MsgBox(0, "Example", "Internet Explorer is running.")
;MsgBox(0,"Process ID",$PID)
ConsoleWrite("["&$PID&"]")
Else
MsgBox(0, "Example", "Unable to get the process id of IE instance")
EndIf
;Disable IE address bar and menu bar
_IEPropertySet ($oIE, "addressbar", False)
_IEPropertySet ($oIE, "menubar", False)
;Click on 'Continue to this website' option if there is any HTTPS certificate Warning
while(_IELinkClickByText ($oIE, "Continue to this website (not recommended)."))
_IELoadWait ($oIE,10000)
wend
;Get the field id and fill with provided value
;$oIE.document.getElementById($formUID).value = $uName
$oIE.document.getElementsByName($formUID).Item(0).value = $uName
$oIE.document.getElementById($formPID).value = $pwd
;$oSubmit = _IEGetObjByName ($oIE, $formSubmit)
$oSubmit = $oIE.document.getElementById($formSubmit)
_IEAction ($oSubmit, "click")
这是我的HTML代码:
<tbody>
<tr>
<td class="login_fields_lable" style="width: 34%;">
<span id="usernameBox" style="white-space: nowrap; vertical-align: middle;" rel="localize[login.LocalUserName]">Local user name:</span>
</td>
<td class="login_fields">
<input autocomplete="off" class="textfield" name="username" id="username" size="30" onkeypress="return checkEnter(event);" type="text"> </td>
</tr>
<tr>
<td class="login_fields_lable" style="width: 34%;">
<span id="passwordBox" style="vertical-align: middle;" rel="localize[login.password]">Password:</span>
</td>
<td class="login_fields">
<input autocomplete="off" class="textfield" name="password" id="password" size="30" onkeypress="return checkEnter(event);" type="password">
</td>
<button id="ID_LOGON" name="ID_LOGON" type="button" onclick="signIn(); return false;" rel="localize[login.loginButton]">Log In</button>
</tr>
</tbody>
由于html页面没有使用form-tag而设计我面临的问题:因为这个原因我使用
$oIE.document.getElementById($formUID).value = $uName
$oIE.document.getElementById($formPID).value = $pwd
从html..plz中读取ID,帮助我...
答案 0 :(得分:0)
你用它来获取元素:
$oIE.document.getElementById($formUID)
变量定义为
$formUID = "username"
但是,HTML脚本中没有输入字段或任何其他带有id="username"
或id="password"
的元素
改变这一点(第3和第5行)
$formUID = "username"
$formPID = "password"
到这个
$formUID = "usernameInput"
$formPID = "passwordInput"
答案 1 :(得分:0)