Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an IE extension which I want to test via automation. The extension adds an item to the Internet Explorer's context menu. Here are the steps I need to be able to automate:

1. Navigate to a specific web page (this is easy)
2. Find and highlight a section of text on that page. (this is easy)
3. Open the context menu (as if the user issued a right-click)
4. Select a particular item in the context menu.

There are any number of ways to achieve the first two steps. I could do it with a WebBrowser control, use the IEDriver as described by Leslie HanksAutomate Internet Explorer, etc. None of these methods allow access to the context menu. I can overload the ShowContextMenu method from AxSHDocVw.AxWebBrowser and display my own context menu but that's not the point. I need to exercise the existing context menu.

One thing (of many) that I don't understand is that if I create a WebBrowser object and navigate to a page, the WebBrowser.ContextMenu is always null even though the page displays just fine and I can right-click in the control and see the default context menu.

Thanks in advance for any clues as to what I'm doing wrong.
Posted

1 solution

My approach to this is to use existing tools for GUI test automation (since I want to automate on the user level and not on the technical detail level of the implementation).
A very useful one is Ranorex[^].
It's a C# API that provides technology independent access to control GUI elements. Usage: Record, export as C#, compile, run. It's affordable for professional users.
 
Share this answer
 
Comments
Paul Hinker 1-Oct-10 9:56am    
I appreciate the response but it doesn't address my question.
Andreas Gieriet 1-Oct-10 10:07am    
I can't see what you are doing wrong...
Show your code and one might help in finding a more concrete answer to your question.
Andreas Gieriet 1-Oct-10 10:25am    
To give you an idea on how to do the above listed activities in Ranorex (C#):
<pre lang="cs">
var IE = repo.IE;
var CtxMenu = repo.CtxMenu;

// open page
IE.Url.Click();
Keyboard.Press("{End}{LShiftKey down}{Home}{LShiftKey up}{Delete}");
Keyboard.Press("http://www.codeproject.com/Questions/114471/IE-Automation-with-a-twist.aspx");
Keyboard.Press(Keys.Return);

// Select area
IE.Page.MoveTo(10,108);
Mouse.ButtonDown(MouseButtons.Left);
IE.Page.MoveTo(345,149);
Mouse.ButtonUp(MouseButtons.Left);

// Copy over context menu
IE.Page.Click(MouseButtons.Right);
CtxMenu.Copy.Click();
<pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900