C#Webbrowser

.Net技术 码拜 6年前 (2015-07-11) 536次浏览 0个评论

最近在写一个自动登录并查询资料的小程序,用C#的Webbrowser实现,目前已经能自动登录了,但是登录后网站要求选择部门代码等其他信息,登录成功后该网站的结构是这样的,一个是框架,包括了基本的一些功能,还有一个子网页是给用户查询资料的。遇到以下两个问题:
1 Webbrowse如何能访问到子网页,我调试的时候找不到;
2 找到该页后如果访问<body>
<xmp class=”pa-ui-fauxtag-xmp”>
<form id=”priceInfoForm”>
<listpanel title=”基本信息” id=”priceBaseInfo_layout”>到xmp class下的控件;
主页的HTML如下:
<form style=”display: none;” id=”opennewwinform”></form>
<script type=”text/x-jquery-tmpl” id=”opennewwintmpl”>
<form id=”opennewwinform” style=”display: none;” action=”${action}” accept-charse=”utf-8″ acceptcharset=”utf-8″ method=”POST”>
{{each params}}
<input name=”${arguments[0]}” value=”${arguments[1]}” />
{{/each}}
</form>
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>XXXX</title>

<link href=”/epcisnba/resources/css/orange/index.css” rel=”stylesheet” type=”text/css” id=”indexlink” />
<style>
.submenuifm {position:absolute; z-index:-1; filter:alpha(opacity=0); opacity:0; width:100%; height:0%;}
</style>
<body style=”text-align: center;”>
<div id=”header”>
<div id=”logo”></div>
<div id=”Loginbar”>
<div id=”Loginbar_bg”></div>
<span id=”Welcome”>您好!

<a href=”javascript:openAnnounceWin(“”/support/systemannounce/exigenceNotice.jsp””);”>紧急通知</a>
<a href=”javascript:openAnnounceWin(“”/support/systemannounce/versionInfo.jsp””);”>版本公告</a>
<a href=”feedbackQuestion.do” target=”_blank”>问题上报</a>
<a href=”./logout.do”>退出</a>
</span>
<div id=”ChangeSkin”>
<ul>
<li><a id=”OrangeSkin” onclick=”changeStyle(“”orange””);” title=”点击更换为橙色皮肤”></a></li>
<li><a id=”BlueSkin” onclick=”changeStyle(“”blue””);” title=”点击更换为蓝色皮肤”></a></li>
<li><a id=”GreenSkin” onclick=”changeStyle(“”green””);” title=”点击更换为绿色皮肤”></a></li>
</ul>
</div>
</div>
<div id=”menu”

>
<ul id=”dropmenu”>

<li class=”menuitem”><span id=”money_bg”></span><a onclick=”openWin(this, “”./quoteandapply/newQuotation.jsp””);”>xxx</a>
<div class=”submenu”>
<iframe class=”submenuifm”></iframe>
<ul>

</ul>
</div>
</li>

<li class=”menuitem”><span id=”willdo_bg”></span><a><span>待处理任务</span></a>
<div class=”submenu”>
<iframe class=”submenuifm”></iframe>
<ul>

<li><a onclick=”openWin(this, “”./workbench/beApplied.jsp””);”>T1</a></li>
<li><a onclick=”openWin(this, “”./workbench/beModified.jsp””);”>T2</a></li>
<li><a onclick=”openWin(this, “”./workbench/unitePrint.jsp””);”>T3</a></li>

<li><a onclick=”return openWin(this, “”./workbench/addNotice.jsp””);”>T11</a></li>
<li><a onclick=”return openWin(this, “”./workbench/beNoticed.jsp””);”>T22</a></li>
<li class=”menuLast”><a onclick=”return openWin(this, “”./workbench/beCircPayment.jsp””);”>T23</a></li>

<li class=”menuLast”><a onclick=”PAWebHelper.showBlankWindow(“”/workbench/forwardAuto.do””,{},{height:””700px””,width:””1000px””})”>ccc</a></li>

<li><a onclick=”openWin(this, “”./workbench/uploadAttachment.jsp””);”>上传附件</a></li>

</ul></div>

</li>
<li class=”menuitem”><span id=”undo_bg”></span><a onclick=”openWin(this, “”./workbench/repealQuote.jsp””);”>DFE</a></li>
<li class=”menuitem”><span id=”search_bg”></span><a>AAA</a>
<div class=”submenu”>
<iframe class=”submenuifm”></iframe>
<ul>
<li><a onclick=”openWin(this, “”./workbench/unapply.jsp””);”>CCC</a></li>
<li><a onclick=”openWin(this, “”./workbench/applied.jsp isNBACenter=false””);”>DDD</a></li>

<li><a onclick=”openWin(this, “”./workbench/beAccepted.jsp””);”>CCC</a></li>

</ul>
</div>
</li>

</ul>
</div>
<div class=”clear”></div>
</div>

<div id=”main” style=”height: 800px”>
<iframe allowTransparency=”true” align=”left” width=”100%” height=”100%” id=”content_iframe” name=”content_iframe” frameborder=”0″ marginwidth=”0″
marginheight=”0″></iframe>
</div>
<script type=”text/javascript” src=”./external/common.js”></script>

<script type=”text/javascript” >

document.getElementById(“”header””).style.display=””block””;
if(getViewModel() && getViewModel().isFromOutSystem == true){
var projectData = getViewModel().projectData;
if(getViewModel().isHiddenMenu){
PAWebHelper.hideItems(“”menu””) ;
}
PAWebHelper.projectCache(“outsystemData”, projectData);
PAWebHelper.projectCache(“systemId”, projectData.systemId);
PAWebHelper.projectCache(“loginUser”,projectData.loginUser);
PAWebHelper.appendCustommade(projectData.systemId, “”system””);
PAWebHelper.projectCache(“isFromOutSystem”, true);
PAWebHelper.openNewWin(getViewModel().tagetURL,getViewModel().postParams)
}else{
document.getElementById(“”header””).style.display=””block””;

PAWebHelper.projectCache(“applyConfigInfo”, {});

PAWebHelper.openNewWin(“/quoteandapply/newQuotation.jsp”);
}

</script>
</body>
</html>

子页面:
<form style=”display: none;” id=”opennewwinform”></form>
<script type=”text/x-jquery-tmpl” id=”opennewwintmpl”>
<form id=”opennewwinform” style=”display: none;” action=”${action}” accept-charse=”utf-8″ acceptcharset=”utf-8″ method=”POST”>
{{each params}}
<input name=”${arguments[0]}” value=”${arguments[1]}” />
{{/each}}
</form>
</script>
<body>
<xmp class=”pa-ui-fauxtag-xmp”>
<form id=”priceInfoForm”>
<listpanel title=”基本信息” id=”priceBaseInfo_layout”>
<layoutpanel columnnum=”2″ columnwidth=”.31,”>
<textfield id=”departmentCodeText” name=”selectedDepartmentCode” fieldlabel=”AF” width=”100″ labelstyle=”width: 140px;”/>
<textfield id=”employeeCodeText” name=”selectedEmployeeCode” fieldlabel=”AD” width=”100″ labelstyle=”width: 140px;”/>

<dictcombox id=”departmentCode” name=”departmentCode” valuefield=”departmentCode” displayfield=”optionDisplay” width=”430px” />
<dictcombox id=”employeeCode” name=”employeeCode” valuefield=”employeeCode” displayfield=”optionDisplay” width=”430px” />
</layoutpanel>

<layoutpanel columnnum=”2″ columnwidth=”.36,”>
<dictcombox id=”channelSource” name=”channelSource” fieldlabel=”CC” displayfield=”channelSourceName” valuefield=”channelSourceCode” width=”140″ lazy=”true” labelstyle=”width: 140px;”/>
<dictcombox id=”businessChannel” name=”businessChannel” fieldlabel=”DD” displayfield=”optionDisplayNew” valuefield=”optionValue” width=”250″ lazy=”true” labelstyle=”width: 140px;”/>
</layoutpanel>
<layoutpanel>
<dictcombox id=”dealerSelect” name=”dealerSelect” fieldlabel=”ER” valuefield=”dealerCode” displayfield=”optionDisplay” width=”430px” labelstyle=”width: 140px;”/>
<dictcombox id=”partnerWorknetSelect” empty=”true” name=”partnerWorknetSelect” fieldlabel=”CV” valuefield=”partnerWorknetCode” displayfield=”optionDisplay” width=”430px” labelstyle=”width: 140px;”/>
</layoutpanel>

<layoutpanel columnnum=”2″ columnwidth=”.46,” >
<radio id=”personnelFlag” name=”personnelType” fieldlabel=”EW” encodetype=”clientType” labelstyle=”width: 165px;” />
<radio id=”ownershipAttributeCode” name=”ownershipAttributeCode” fieldlabel=”RT” encodetype=”ownershipAttributeCode” value=”03″ labelstyle=”width: 191px;” />

<radio id=”usageAttributeCode” name=”usageAttributeCode” fieldlabel=”WE” encodetype=”usageAttributeCode” value=”02″ labelstyle=”width: 84px;” />
<radio id=”isFleetBusiness” name=”isFleetBusiness” fieldlabel=”YU” encodetype=”yesOrNoType1″ value=”0″ required=”true” labelstyle=”width: 110px;”/>
</layoutpanel>

<layoutpanel columnnum=”2″ columnwidth=”.46,” id=”rateInfoPanel” >
<dictcombox id=”insuranceType” fieldlabel=”CC” name=”insuranceType” encodetype=”insuranceType” value =”1″/>
<dictcombox id=”rateClassFlag” fieldlabel =”DD” name=”rateClassFlag” value=”08″ encodetype=”rateClassFlag” />
</layoutpanel>

<layoutpanel columnnum=”2″ id=”opportunityInfo” columnwidth=”.35,”>
<textfield id=”opportunityCode” fieldlabel=”SFE” class=”text_noborder” width=”110px” />
<textfield id=”opportunityName” fieldlabel=”YU” class=”text_noborder” width=”400px” labelstyle=”width:70px;” />
</layoutpanel>
</listpanel>

<div class=”btncenter”>
<button value=”确定” id=”OKBtn” />
<button value=”重置” id=”ResetBtn” />
</div>
</form>
</xmp>
</body>
</html>
上面的html是我用Http analyzer抓到的。

10分

看不出问题出在哪里.

20分

很早以前用过webbrowser,现在也忘了,帮顶起
 
感谢各位捧场,篇幅有点儿长。那个子页面应该是用脚本打开的,现在的问题是我如何才能找到那个页面呢?
 
大虾猛哪里去啦?昨天我直接打开/quoteandapply/newQuotation.jsp这个页面,发现能正常找到我需要的所有控件,但是登录后后面的网页又打不开了,不知道是不是权限问题?此外我猜想那个子页面可能是个组件,只不过在浏览器这边转换成HTML各式显示而已,所以WebBrowser无法直接获取。

20分

找下JS脚本里面有没有子页面的地址?
 
PAWebHelper.openNewWin(“/quoteandapply/newQuotation.jsp”);貌似这句是打开子页面的方法,但是我直接打开这个路径,网页出错了,如果直接用浏览器打开就是正常的。
 
问题解决了,直接打开那个子网页地址就可以了。但是现在有有一个问题,HTML中的下拉框如何获取和设置值呢?我采用的是mshtml.IHTMLElement ?

25分

子项的 selected=true;
 
引用 8 楼 wawd74520 的回复:

子项的 selected=true;

能不能详细一点,十分感谢!

25分

引用 9 楼 therry_ding 的回复:
Quote: 引用 8 楼 wawd74520 的回复:

子项的 selected=true;

能不能详细一点,十分感谢!

http://bbs.csdn.net/topics/330220151

 
问题解决了,感谢楼上给位。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C#Webbrowser
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!