想做个自动登录我公司内网OA的小程序,但遇到了点小问题,我的程序现在可自动填写OA首页用户登录中用户名和密码,但死活不能模拟点击“登陆”按钮click事件,而另外做的两个自动提交的内网就可以模拟“登陆”按钮click事件。我查了一下OA网页源文件发现如下网页代码片段,我该怎么模拟点击源文件中checkname()事件呢?拜托大家帮帮我!
我的程序代码:
private void LoadOA()
{
try
{
SHDocVw.InternetExplorer IE = new InternetExplorer();
IE.Visible = true;
string URL = textBox1.Text;
object nullArg = null;
IE.Navigate(URL, ref nullArg, ref nullArg, ref nullArg, ref nullArg); System.Threading.Thread.Sleep(1000);
//得到IE的文档对象模型
mshtml.IHTMLDocument2 DOM = (mshtml.IHTMLDocument2)IE.Document;
//用户名
mshtml.IHTMLInputTextElement txtUserName = (mshtml.IHTMLInputTextElement)DOM.all.item("username", null);
txtUserName.value = textBox2.Text;
//密码
mshtml.IHTMLInputTextElement txtPwd = (mshtml.IHTMLInputTextElement)DOM.all.item("password", null);
txtPwd.value = textBox3.Text;
//登录
mshtml.HTMLInputElement btnLogin = (mshtml.HTMLInputElement)DOM.all.item("这里应该填写网页源文件中【登陆】按钮的ID,可是没有啊,就有下面的给出的相关源文件信息", 0);
System.Threading.Thread.Sleep(1000);
btnLogin.click();
}
catch (Exception) { }
}<FORM method="POST" action="http://abc.com.cn/pkmslogin.form@ab" name="LoginForm"
onsubmit="return checkname()"></FORM>登陆按钮的属性为:
<TR bgColor=#eff7ff>
<TD colSpan=3 height=30>
<DIV align=center><INPUT TYPE="SUBMIT"
style=" FONT-FAMILY: '宋体'; tabindex=3 VALUE="登录"></DIV>
</TD>
</TR><script language="Javascript">
function trim(str) {
for(var i = 0 ; i<str.length && str.charAt(i)==' ' ; i++ ) ;
for(var j =str.length; j>0 && str.charAt(j-1)==' ' ; j--) ;
if(i>j) return '';
return str.substring(i,j);
}
function checkname()
{
if(document.LoginForm.userID.value=="" || document.LoginForm.password.value==""){
alert("用户名或密码不正确,请重新输入");
return false;
}
document.LoginForm.userID.value=trim(document.LoginForm.userID.value);
}
</script>
我的程序代码:
private void LoadOA()
{
try
{
SHDocVw.InternetExplorer IE = new InternetExplorer();
IE.Visible = true;
string URL = textBox1.Text;
object nullArg = null;
IE.Navigate(URL, ref nullArg, ref nullArg, ref nullArg, ref nullArg); System.Threading.Thread.Sleep(1000);
//得到IE的文档对象模型
mshtml.IHTMLDocument2 DOM = (mshtml.IHTMLDocument2)IE.Document;
//用户名
mshtml.IHTMLInputTextElement txtUserName = (mshtml.IHTMLInputTextElement)DOM.all.item("username", null);
txtUserName.value = textBox2.Text;
//密码
mshtml.IHTMLInputTextElement txtPwd = (mshtml.IHTMLInputTextElement)DOM.all.item("password", null);
txtPwd.value = textBox3.Text;
//登录
mshtml.HTMLInputElement btnLogin = (mshtml.HTMLInputElement)DOM.all.item("这里应该填写网页源文件中【登陆】按钮的ID,可是没有啊,就有下面的给出的相关源文件信息", 0);
System.Threading.Thread.Sleep(1000);
btnLogin.click();
}
catch (Exception) { }
}<FORM method="POST" action="http://abc.com.cn/pkmslogin.form@ab" name="LoginForm"
onsubmit="return checkname()"></FORM>登陆按钮的属性为:
<TR bgColor=#eff7ff>
<TD colSpan=3 height=30>
<DIV align=center><INPUT TYPE="SUBMIT"
style=" FONT-FAMILY: '宋体'; tabindex=3 VALUE="登录"></DIV>
</TD>
</TR><script language="Javascript">
function trim(str) {
for(var i = 0 ; i<str.length && str.charAt(i)==' ' ; i++ ) ;
for(var j =str.length; j>0 && str.charAt(j-1)==' ' ; j--) ;
if(i>j) return '';
return str.substring(i,j);
}
function checkname()
{
if(document.LoginForm.userID.value=="" || document.LoginForm.password.value==""){
alert("用户名或密码不正确,请重新输入");
return false;
}
document.LoginForm.userID.value=trim(document.LoginForm.userID.value);
}
</script>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货