Click to See Complete Forum and Search --> : Webbrowser giving me issues...
Silo1337
July 11th, 2009, 10:59 AM
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:
private void Form1_Load(object sender, EventArgs e){
WebBrowser1.Navigate("www.google.com");
}
Then, here's my document completed code:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){
HtmlDocument doc = this.WebBrowser1.Document;
}
This is the error I am getting:
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?
memeloo
July 11th, 2009, 03:33 PM
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.
Silo1337
July 12th, 2009, 10:33 AM
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:
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:
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!
memeloo
July 12th, 2009, 11:14 AM
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
Silo1337
July 12th, 2009, 12:43 PM
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:
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!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.