HtmlElement.OuterHtml.Replace() fails with COM exception
-
I'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?
-
I'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?
Perhaps you should start by mentioning what you are doing? Are you changing the page in a browser from another program? Do you have a browser component in your program that shows the page you are trying to change? Are you writing a client side component that is changing the page it is running in? --- b { font-weight: normal; }
-
Perhaps you should start by mentioning what you are doing? Are you changing the page in a browser from another program? Do you have a browser component in your program that shows the page you are trying to change? Are you writing a client side component that is changing the page it is running in? --- b { font-weight: normal; }
Ok, 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.