提取不到当前页面文本~求助!!!
前提:当用户登录信息错误时,网页将弹出图中的红字提示信息我想用以下代码段来获取图中的红字部分信息;
但不管用户登录信息正确与否,MsgBox输出内容均为“”(空)!
个人分析,可能是因为MsgBox输出的为点击“登录”按钮之前的页面内容。
“登录”按钮点击之前红字部分并未弹出,所以永远获取不到?
是否该在第10行增加刷新页面的代码?
若加,怎么加?
或者是因为别的什么原因?
求高手指点下。感激不尽。。。折磨我好多天了这个问题。#include <IE.au3>
$oIE_Login =_IECreate("http://www.xxx.com/Login.aspx","url")
$sUserName = _IEGetObjById($oIE_Login,"txtUserName")
_IEFormElementSetValue($sUserName,"UserName")
$sPassWord = _IEGetObjById($oIE_Login,"txtPassWord")
_IEFormElementSetValue($sPassWord,"pswd")
$BtnLogin = _IEGetObjById($oIE_Login,"btnLogin")
_IEAction($BtnLogin,"click")
;添加刷新页面的代码??
Sleep(2000)
$Ele = _IEGetObjById($oIE_Login,"lblMsg")
MsgBox(0,"元素html",$Ele.outerhtml)这是运行以上代码段后的页面。此时MsgBox输出内容为空。
没有网页代码{:face (394):} 怎么又起新帖?网页地址或者网页源码都没给 回复 3# chamlien
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
XXX有限责任公司OA平台登陆
</title><meta http-equiv="X-UA-Comoatible" content="IE=6" /><link href="Styles/Login.css" rel="stylesheet" type="text/css" /></head>
<body>
<form name="form1" method="post" action="Login.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTAyNDA1ODg1OGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFCGJ0bkxvZ2lu068Le2upiaqIhyGnou9DeDj0F7g=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/WebResource.axd?d=KTAvAD3X6-imDzKZLGyrd9Oo-f4vzuLKKgZcSeiWFqaANMYCXBsEieuIsvZEa82_hIHfw8O52Sa-7Lkj3QmGhrm0hhM1&t=635839671704531250" type="text/javascript"></script>
<script src="/WebResource.axd?d=9HO8ofLcAbWXXi_mvqu84CyBkUniqqugBBQdUO0rIEoxaBl3EkvKMvMYgtLolWc5p3FyRpATbhKBLh-8BwOkTHUqXLw1&t=635839671704531250" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALk5vmcDAKl1bKzCQK1qbSWCwKC3IeGDE8FsHl3hAJwnlMQbRRyaZxcQXXy" />
</div>
<table cellpadding="0" cellspacing="0" width="100%"
style="margin-top: 200px">
<tr>
<td align="right" width="45%">
<imgsrc="images/login/logo.jpg" />
</td>
<td align="left">
<div id="right">
<table style="width: 100%;">
<tr>
<td colspan="3" align="left">
<img src="images/login/key.jpg" /><span class="txtlogin">登陆</span>
</td>
</tr>
<tr>
<td>
用户名:
</td>
<td>
<input name="txtUserName" type="text" id="txtUserName" style="border-color:#336699;border-width:1px;border-style:solid;height:24px;width:157px;" /><span id="RequiredFieldValidator1" style="color:Red;visibility:hidden;">*</span>
</td>
<td>
<img id="help" src="images/login/Sleek_XP_010.png" alt="" style="cursor: pointer; display: none;"
title="点击获取用户名" onclick="change()" />
</td>
</tr>
<tr>
<td>
密 码:
</td>
<td>
<input name="txtPassWord" type="password" id="txtPassWord" style="border-color:#336699;border-width:1px;border-style:solid;height:24px;width:157px;" /><span id="RequiredFieldValidator2" style="color:Red;visibility:hidden;">*</span>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input type="image" name="btnLogin" id="btnLogin" src="images/login/btn_login.jpg" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnLogin", "", true, "", "", false, false))" style="border-width:0px;" />
</td>
<td align="left">
<a id="btnModify" href="ModifyPassword.aspx">
<img style="border: 0;" src="images/login/btn_modify.jpg" /></a>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
<span id="lblMsg" style="color:Red;"></span>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="center" valign="bottom" height="200px">
<table border="0" cellpadding="5px" cellspacing="5px" style="text-align: center">
<tr>
<td colspan="2" style="font-size: large">
内网系统问题咨询
</td>
</tr>
<tr>
<td>
生产管理系统
</td>
<td>
王某某
</td>
</tr>
<tr>
<td>
人力资源系统,科研管理系统
</td>
<td>
吴某某
</td>
</tr>
<tr>
<td>
其他内网系统
</td>
<td>
柯某某
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" valign="middle" align="center"
style="color: #666666;font-size: 12px;" height="50px">
版权所有 XXX有限责任公司 cqjm© 2011 All Rights Reserved
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
var Page_Validators =new Array(document.getElementById("RequiredFieldValidator1"), document.getElementById("RequiredFieldValidator2"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var RequiredFieldValidator1 = document.all ? document.all["RequiredFieldValidator1"] : document.getElementById("RequiredFieldValidator1");
RequiredFieldValidator1.controltovalidate = "txtUserName";
RequiredFieldValidator1.errormessage = "*";
RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator1.initialvalue = "";
var RequiredFieldValidator2 = document.all ? document.all["RequiredFieldValidator2"] : document.getElementById("RequiredFieldValidator2");
RequiredFieldValidator2.controltovalidate = "txtPassWord";
RequiredFieldValidator2.errormessage = "*";
RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator2.initialvalue = "";
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
//]]>
</script>
</form>
</body>
</html>
回复 2# 1361739590
网页源码见4楼 你这个登录过程是这样的,点登陆按钮调用js的WebForm_DoPostBackWithOptions()函数,js重写了lblMsg元素的value值。你的$oIE_Login是接收不到这个改变的。解决方案应该是登录后你用另一个变量再attach这个网页,就能得到变化后的lblMsg元素。 楼上的应该是正解要重新获取这个网页 回复 6# tank
测试过,_IEAttach重新attach这个网页也不行~~
感谢回贴
继续求助!! 你的网址打不开不好试 你的网址打不开不好试IE几 注意网页是否采用框架结构了!
页:
[1]