A little background - I'm a QA automation engineering(working with Mercury/HP's Quick Test Professional) who is just delving into some C# programming to solve some of our issues. I would consider my skillset at the level: "Trained monkey, without the training".
We have a .Net application that has some browser controls somehow imbedded such that our automation tool can only access it in a very limited fashion. Through a lot of Googling, I have discovered if I create a IHTMLDocument2 interface to the object I can access virtually everything. I've verified that I can create a C# .DLL and call that with our testing tool.
The C# programm I have created, I'm able to return the object "htmlDocument", write out various properties like innerText.
I am having trouble with the .click method. It partally works in such a way that the link is clicked and the required window is opened. However, the following two things happen:
1 - The code appears to "hang" in the .click method until I close the window that the .click method opened up.
2 - If I take out the Try/Catch block, an exception is thrown when I close the window. The exception is:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80004004): Operation aborted
My guess is that the .click method is somehow simulating some type of mousedown and mouseup combination, but for whatever reason, it is not completing it.
Any suggestions how to work around this?
Thanks in advance for any help.
-Ed
Expand|Select|Wrap|Line Numbers
- using System;
- using McK.Automation.Text;
- using System.Runtime.InteropServices;
- using mshtml;
- using System.Collections;
- using System.Text.RegularExpressions;
- namespace testApplication
- {
- /// <summary>
- /// Summary description for Class1.
- /// </summary>
- class testApplication
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main(string [] args)
- {
- ObjectText Text = new ObjectText();
- IHTMLDocument2 htmlDocument = Text.ReturnIEDocumentObject(656656);
- //
- //Capture the innerText property of the object
- //
- string innerText = htmlDocument.body.innerText;
- Console.WriteLine("Value: {0}", innerText.ToString());
- IHTMLElementCollection links = htmlDocument.links;
- foreach (HTMLAnchorElementClass el in links)
- {
- Console.WriteLine("Value: {0}", el.innerText);
- Match m = Regex.Match(el.outerHTML, ".*aspirin.*");
- if (m.Success)
- {
- Console.WriteLine("Value: {0}", el.innerText);
- try
- {
- el.
- el.click();
- break;
- }
- catch
- {
- }
- }
- }
- }
- }
- }