Webbrowser giving me issues...
So I am trying to have a window with Web Browser control in which I will be filling forms on various websites. This is my current code to load google, which works fine:
Code:
private void Form1_Load(object sender, EventArgs e){
WebBrowser1.Navigate("www.google.com");
}
Then, here's my document completed code:
Code:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){
HtmlDocument doc = this.WebBrowser1.Document;
}
This is the error I am getting:
Code:
Error 1 Cannot implicitly convert type 'object' to 'System.Windows.Forms.HtmlDocument'. An explicit conversion exists (are you missing a cast?) C:\Users\Admin\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 27 32 WindowsFormsApplication1
Can someone please explain to me what I am doing wrong?
Re: Webbrowser giving me issues...
mhmm, strange, msdn says that WebBrowser.Document returns a HtmlDocument so I should work. are you sure this is the right code? I've tested it and it works on my machine.
Re: Webbrowser giving me issues...
Quote:
Originally Posted by
memeloo
mhmm, strange, msdn says that WebBrowser.Document returns a HtmlDocument so I should work. are you sure this is the right code? I've tested it and it works on my machine.
This is the exact code I have in my compiler yet it keeps throwing that error for whatever reason. I'm programming in Visual C#, have included the browser control and everything. I tried using the web browser control in Visual Basic and was able to fill forms perfectly fine using similar code. I'm not sure why this isn't working for me, the following code that someone gave me doesn't work either:
Code:
webBrowser1.Document.GetElementById("Email").SetAttribute("value", "empa7hy");
I am absolutely stumped as to what the trouble is! Here is the error I get with this:
Code:
Error 1 'object' does not contain a definition for 'GetElementById' and no extension method 'GetElementById' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) C:\Users\Admin\Desktop\Bot\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 26 34 WindowsFormsApplication1
I don't want to have to program my stuff in Visual Basic, but it looks like I might have to since C# is being a real pain!
Re: Webbrowser giving me issues...
what WebBrowser are you using?
WebBrowser class from System.Windows.Forms
or something else like
WebBrowser control from System.Windows.Controls
because the second one returns a Document of type object and I've tested the first one
Re: Webbrowser giving me issues...
Ah, I got it. When you mentioned that, I went to take a peak and I happened to be using the "Microsoft Web Browser" control rather than the standard web browser control. All is well now, and this code works perfectly:
Code:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument DOC = this.webBrowser1.Document;
DOC.All["q"].SetAttribute("value", "Random Search");
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("www.google.com");
}
My search field is now set to "Random Search" upon the page being loaded. Thank you so much!