在做桌面程序时,使用到了webbrowser 在这里要自动填写表单,这个表单的提交按钮的代码是这样的
<input onmouseover="this.style.backgroundColor='#FFC864'" style="border: 1px solid black; height: 20px; width: 100px; background-color: rgb(243, 243, 243);" onfocus="this.blur()" onmouseout="this.style.backgroundColor='#f3f3f3'" onclick="checkform(addmsg)" value="发 表" type="button">   没有ID属性,我本来想用form 的submit 事件提交的,但是不能成功,我想找到这个按钮,调用它的click()事件。由于没有ID
只能用循环来找
foreach (HtmlElement sub in doc.All)
            {
                if (sub != null && sub.GetAttribute("value").Equals("发 表"))
                {
                    model.Submit = sub;
                }
            }
这样造成程序运行到这一段时很慢,虽然能实现但不爽,有没有更好的方法来取这个按钮呢?在线等

解决方案 »

  1.   

    其实如果能得到它的form 也行,但是它的代码写的很怪我贴一下
    <table class="p9" align="center" border="0" cellpadding="4" cellspacing="1" width="98%"> <form name="addmsg" onsubmit="return false;" action="http://bjmsg.focus.cn/group/house_forum_add.php" method="post"></form> <input name="returnhost" value="bjmsg.focus.cn" type="hidden">
    <input name="reply_msg_id" value="168865170" type="hidden">
    <input name="group_id" value="2818" type="hidden">
    <input name="from_group_id" value="2818" type="hidden">
    <input name="returnhost" value="bjmsg.focus.cn" type="hidden">
    <input name="sub_id" value="0" type="hidden">
    <input name="hide_city" value="2" type="hidden">
                    ..................省略一些不重要的
    <tr>
    <td colspan="2" height="30"> <input onmouseover="this.style.backgroundColor='#FFC864'" style="border: 1px solid black; height: 20px; width: 100px; background-color: rgb(243, 243, 243);" onfocus="this.blur()" onmouseout="this.style.backgroundColor='#f3f3f3'" onclick="checkform(addmsg)" value="发 表" type="button">   </td>
    </tr>
    </table>
    在取到from后里面的input是取不到的,它的input都写在了from的外面有什么好办法没?
      

  2.   

    其实如果能得到它的form 也行,但是它的代码写的很怪我贴一下
    <table class="p9" align="center" border="0" cellpadding="4" cellspacing="1" width="98%"> <form name="addmsg" onsubmit="return false;" action="http://bjmsg.focus.cn/group/house_forum_add.php" method="post"></form> <input name="returnhost" value="bjmsg.focus.cn" type="hidden">
    <input name="reply_msg_id" value="168865170" type="hidden">
    <input name="group_id" value="2818" type="hidden">
    <input name="from_group_id" value="2818" type="hidden">
    <input name="returnhost" value="bjmsg.focus.cn" type="hidden">
    <input name="sub_id" value="0" type="hidden">
    <input name="hide_city" value="2" type="hidden">
                    ..................省略一些不重要的
    <tr>
    <td colspan="2" height="30"> <input onmouseover="this.style.backgroundColor='#FFC864'" style="border: 1px solid black; height: 20px; width: 100px; background-color: rgb(243, 243, 243);" onfocus="this.blur()" onmouseout="this.style.backgroundColor='#f3f3f3'" onclick="checkform(addmsg)" value="发 表" type="button">   </td>
    </tr>
    </table>
    在取到from后里面的input是取不到的,它的input都写在了from的外面有什么好办法没?
      

  3.   

    doc.getElementsByTagName("input")会少一些吧
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/