I can not fix the error anyone can help me? ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(" http://www.httpsurf.com/ ");
//the debugger tells me that the error in this line
webBrowser1.Document.GetElementById("url").InnerText = textBox1.Text;
webBrowser1.Document.GetElementById("go").InvokeMember("Click");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Loading

VulpesRank #55 · 29.2K reputationPosted Nov 11, 2011, 8:46 AM EST
To prevent the exception, you'd therefore need to do this:
if (webBrowser1.Document.GetElementById("url") != null)
{
}
Jean PaulRank #32 · 38.5K reputationPosted Nov 11, 2011, 8:46 AM EST
Following is the corrected code.
Please note that you have to ensure the event is not called multiple times (delegate, invoking click)
Posted Nov 11, 2011, 9:09 AM EST
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 11, 2011, 9:49 AM EST
webBrowser1.Navigate(" http://www.httpsurf.com/ ");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
// here is the event
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("Url").InnerText = textBox1.Text;
}
Sam HobbsRank #107 · 20.5K reputationPosted Nov 11, 2011, 7:20 PM EST
Second, please see my article Introduction to Web Site Scraping.