网站按钮点击空例外

时间:2016-03-02 20:18:38

标签: c# html

尝试在c#

中单击某个站点的按钮时,我收到null异常

以下是代码:

WebBrowser webb = new WebBrowser();

webb.Navigate(" http://10.0.3.190:8880/guest/s/default/? ID = 9C:广告:97:CB:9D:15安培; AP = DC:9F:分贝:B0:AB:64& T公司= 1456946961&#34);

        HtmlElement button = webb.Document.GetElementById("connect");
        if (button == null)
        {
            MessageBox.Show(" id not found");

        }
            else if (button != null)
            {
            MessageBox.Show(" id found");
             button.InvokeMember("click");


            }

        }

Source For Button

这是网站的完整HTML:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title>Action Required - Guest Access</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="http://10.0.3.190:8880/guest/s/default/reset-min.css" />
<link rel="stylesheet" type="text/css" href="http://10.0.3.190:8880/guest/s/default/styles.css" />
<script type="text/javascript" src="http://10.0.3.190:8880/guest/s/default/js/jquery.min.js"></script>
<script type="text/javascript" src="http://10.0.3.190:8880/guest/s/default/js/guest.js"></script>
</head>
<body class="login-page">
<!-- see README.txt for HTML customization instructions -->
<div class="page-content" style="padding-top:100px;">
<div class="login-content content-box">

</div>

<div class="login-content content-box">
<form name="input" method="post" action="login">
<div class="tou-box">
<h2>Terms of Use</h2>
<div class="tou-wrapper" id="tou">
<div class="tou">
<p>Terms of Use</p>
<p>By accessing the wireless network, you acknowledge that you're of legal age, you have read and understood and agree to be bound by this agreement</p>
<ul>
<li>The wireless network service is provided by the property owners and is completely at their discretion. Your access to the network may be blocked, suspended, or terminated at any time for any reason.</li>
<li>You agree not to use the wireless network for any purpose that is unlawful and take full responsibility of your acts.</li>
<li>The wireless network is provided &quot;as is&quot; without warranties of any kind, either expressed or implied. </li>
</ul>
</div>
</div>
<fieldset class="accept-tou">
<input id="accept-tou" type="checkbox" checked="checked" name="accept-tou" value="yes" />
<label class="normal" >I accept the <a href="javascript:void(0)" id="show-tou">Terms of Use</a></label>
</fieldset>
<div class="form-controls">
<!-- submit (only for no authentication) -->
<input name="connect" type="submit" value="Connect" id="connect" class="button requires-tou" />
</div>
</div>
</form>
</div>
</div>

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('input').keypress(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if ( (code==13) || (code==10)) {
jQuery(this).blur();
return false;
}
});
});

$(function() {
$('#tou').hide();
$('#show-tou').click(function() {
$('#tou').show();
});
$('#accept-tou').click(function() {
if (!$('#accept-tou').checked()) {
$('input.requires-tou').disable();
}
else {
$('input.requires-tou').enable();
}
})
});
</script>

</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

冒号运算符在网址中保留。您需要对它们进行编码(如%3A,或遵循下面的一些建议。

这可能是重复的: Using a colon (:) in a url with ASP.NET/IIS