|
-
July 11th, 2009, 10:59 AM
#1
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?
Last edited by Silo1337; July 11th, 2009 at 11:27 AM.
-
July 11th, 2009, 03:33 PM
#2
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.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
July 12th, 2009, 10:33 AM
#3
Re: Webbrowser giving me issues...
 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!
-
July 12th, 2009, 11:14 AM
#4
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
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
July 12th, 2009, 12:43 PM
#5
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|