url="https://ipv4.google.com/sorry/IndexRedirect?continue=https://www.google.com/search%3Fq%3Dstackoverflow%2B%26rlz%3D1C1KMZB_enTR561TR561%26oq%3Dstac%26aqs%3Dchrome.1.69i59l3j69i60j69i57j69i60.5208j0j7%26sourceid%3Dchrome%26espv%3D210%26es_sm%3D122%26ie%3DUTF-8";
webBrowser1.Navigate(url);
if (url.Contains("ipv4.google.com"))
{
frm2.ShowDialog();
Application.DoEvents();
webBrowser1.Document.GetElementById("captcha").SetAttribute("value", frm2.code);
webBrowser1.Document.GetElementById("submit").InvokeMember("click");
}
例外是:
指定的演员表无效。
在
webBrowser1.Document.GetElementById("captcha").SetAttribute("value", frm2.code);
答案 0 :(得分:0)
我认为您的webBrowser1在尝试访问时没有加载文档。您应该将if-clause中的代码放入webBrowser1.Navigate
的eventhandler中。此时webBrowser已将文档完全加载到URL
答案 1 :(得分:0)
在文档准备好加载时使用。
string url = "https://ipv4.google.com/sorry/IndexRedirect?continue=https://www.google.com/search%3Fq%3Dstackoverflow%2B%26rlz%3D1C1KMZB_enTR561TR561%26oq%3Dstac%26aqs%3Dchrome.1.69i59l3j69i60j69i57j69i60.5208j0j7%26sourceid%3Dchrome%26espv%3D210%26es_sm%3D122%26ie%3DUTF-8";
WebBrowser webBrowser1 = new WebBrowser();
this.Controls.Add(webBrowser1);
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Navigate(url);
if (url.Contains("ipv4.google.com"))
{
webBrowser1.DocumentCompleted += handler;
}
private void handler(object sender, WebBrowserDocumentCompletedEventArgs e)
{
frm2.ShowDialog();
webBrowser1.Document.GetElementById("captcha").SetAttribute("value", frm2.code);
webBrowser1.Document.GetElementById("submit").InvokeMember("click");
webBrowser1.DocumentCompleted -= handler;
};