当我使用IE10 windows8时,自动脚本没有从html页面获取id值?

时间:2014-05-23 13:16:43

标签: internet-explorer-10 autoit

以下代码从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&nbsp;user&nbsp;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&nbsp;In</button>
    </tr>
</tbody>

由于html页面没有使用form-tag而设计我面临的问题:因为这个原因我使用

    $oIE.document.getElementById($formUID).value = $uName
$oIE.document.getElementById($formPID).value = $pwd

从html..plz中读取ID,帮助我...

2 个答案:

答案 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)

  1. 打开IE
  2. 转到&#34;工具&#34;
  3. 转到&#34;互联网选项&#34;
  4. 点击&#34;安全&#34;标签
  5. 取消选中&#34;启用保护模式&#34;复选框
  6. 重新启动IE并尝试使用您的脚本