Please see this link for the rest of this saga. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=391357&SiteID=1
cweeks78681
Posts
-
MSHTML: Howto access elements within a <IFRAME> -
MSHTML: Howto access elements within a <IFRAME>I am using the Webbrowser control in VS 2005 C# Express to automate the navigation of pages on a partner's web site. The first page contains an element: <iframe style='width:40; height:40'; align='center' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' id='xyzlogin' name='xyzlogin' src='https://www.xyzcorp.com/accounts/ServiceLogin'> Within that frame I need to access these three elements:
-
Porting web navigator from VB6 to VS2005 C#Here's the code that properly selects an element from the listbox: HtmlElement eltCountryList = webBrowser1.Document.GetElementById("countryList"); HtmlElementCollection eltOptions = eltCountryList.GetElementsByTagName("option"); foreach (HtmlElement op in eltOptions) { op.SetAttribute("selected", ""); // de-select all items in the list } eltOptions[25].SetAttribute("selected", "True"); // set "United States" as the selected item
-
Porting web navigator from VB6 to VS2005 C#I don't have access to my development system at the moment to try this out. So, I would appreciate some input as to whether or not this might work: IHTMLDocument3 iDoc3 = (IHTMLDocument3)wb1.Document.DomDocument; IHTMLSelectElement eltCountryList = iDoc3.getElementById("countryList"); eltCountryList.selectedIndex = 25; For now, just ignore the absence of error checking for null pointer values. Is this about the right approach? Will I be able to modify the element's 'selectedIndex' property without any kind of initialization or setup code (sometimes it looks like the HTMLDocument contained in the webbrowser control is read-only)? Do I need to iterate through each element in the list using the IHTMLOptionElement interface and set the 'selected' property to false?
-
Porting web navigator from VB6 to VS2005 C#I am porting a VB 6.0 application to C# that automates navigation of multiple web pages within a site and extracts information from some of the pages. One of the pages contains a listbox containing a number of countries. The default value that is set is not the value I need to use. The HTML in the web page looks like this: All Countries and Territories ------ Australia Austria Belgium Brazil Canada China Denmark Finland France Germany Hong Kong Italy Japan Netherlands Norway Portugal Singapore South Korea Spain Sweden Switzerland Taiwan United Kingdom United States In VB6 the selected value is changed this way: ' De-select the first (default) value in the list wb1.All("country").Options(0).Selected = False ' Select the 26th item (zero-based index) in the list wb1.All("country").selectedIndex = 25 wb1 is an HTMLDocument object. I cannot figure out how to access the Options collection or the selectedIndex property with the .NET 2.0 Webbrowser object. Any ideas how I can do this in C#?
-
How to use IHTMLDocument2 with .NET 2.0 Webbrowser> What does that have to do with setting designMode to ON? It was a shot in the dark. I thought maybe the HTMLDocument was in some kind of read-only state because I have NEVER found a way to modify a page in the web browser. Some kind of exception is always thrown. One said something about an access violation.
-
How to use IHTMLDocument2 with .NET 2.0 WebbrowserVS 2005 C# Express, .NET 2.0 The following code causes the Body member of the Webbrowser control to be set to null. Why? mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2) this.webBrowser1.Document.DomDocument; doc2.designMode = "On"; I am trying to programmatically select an element () in a web page listbox () the way a user would with the left mouse button. So, far I've found nothing that will do this.
-
Reference/tutorial material for using MSHTML from C#?Would anyone like to recommend a book or Internet-based resource where I could learn to use MSHTML from C#? I need to know how get access to the IHTMLDocument* interface pointers, how to call them and what pitfalls to avoid in the use of unmanaged interface pointers in a C# application. I'm learn-by-example kind of guy, so the more practical examples I can look at the better. I've been forced into this position by the limited capabilities of the .NET 2.0 Webbrowser control in VS 2005 C# Express.
-
Is the VS 2005 Webbrowser really ready for prime time?I am trying to use the Webbrowser control that is available in VS 2005 C# Express (.NET 2.0) to automate navigation through a set of web pages programmatically. I've run into two situations where I cannnot access the OuterHtml property of an HtmlElement. Looking at the debugger seems to say that some kind of underlying exception occurs. 1. I want to select an item in a listbox on a web page by changing the OuterHtml of two of the member elements from: to The attempt to remove the 'selected' string from the first entry fails completely and even messes up the entire listbox 2. I want to iterate through the frames on a web page to find the one I want to enter some text into. When I try to access (read, not write) the OuterHtml property of a frame to see if it is the one I want I see some kind of access violation in the debugger. Shouldn't this work? Does it make sense to try to use the unmananged interfaces IHTMLDocument, IHTMLDocumet2, etc. when the Webbrowser fails like this? Can I mix the use of the Webbrowser control with use of the unmanaged interfaces?
-
Programmatically pressing a webBroswer buttonI don't have access to my code at the moment but I have successfully done this by navigating to the button's HtmlElement object in the document and then invoking the InvokeMember() method: HtmlElement elt = webbrowser1.Document.GetElementsByTagName("INPUT")[0]; elt.InvokeMember("Click"); Now, that's rough approximation. You may have to make to changes to get it to compile. But you get the idea. -- modified at 17:15 Wednesday 26th April, 2006
-
HtmlElement.OuterHtml.Replace() fails with COM exceptionOk, fair enough, I am automating navigation through a set of web pages by putting the NET 2.0 Webbrowser control on a dialog. When I get to the third page in the sequence I need to change the default item in a listbox on the web page to the item that I know in advance I want selected. I've been successful in using InvokeMember("Click") to click a button on a web page but I have not been able to "click" on an item in a list in order to select it.
-
HtmlElement.OuterHtml.Replace() fails with COM exceptionI've tried asking this on microsoft.public.dotnet.languages.csharp, but I am getting no response. Maybe I'm getting lost in the traffic. So, let's try it here. Dev env: VS 2005 C# Express, .Net Framework 2.0 I am trying to programmatically select an item in a listbox on a web page. The first thing I do is go through and de-select any selected items. The OuterHtml field of a selected element in the listbox looks something like this: Default item I want to simply remove the the term 'selected' this way: elt.OuterHtml = elt.OuterHtml.Replace("selected",""); This results in OuterHtml being set to: Notice: 1) the 'selected' term is untouched, 2) the visible text has been removed. After the assignment I can see in the debugger that one of the members of the HtmlElement object (OffsetParent, I think) has a string indicating some kind of COM Interop services exception. The MSDN documentation at http://tinyurl.com/edbln does contain this warning: "If you assign a new value to OuterHtml, the current element reference will become invalid; it will not reflect the name, properties and child content of the HTML you have just assigned." but I don't really understand what that means. Is it possible to change the HTML in a web page? Am I going about it the wrong way? Is there some kind of initialization or setup call I am supposed to make? Is it just a bug in .NET 2.0?