Click to See Complete Forum and Search --> : Navigation within a webpage


wisebulls
August 9th, 2008, 12:22 PM
Hi Gurus,

My application (coded in C#) navigates to a webpage which contains a drop down box.

Can I code it to repeat certain keystrokes from here ... for example, 7 DOWN, TAB, ENTER, 5 TAB, 3 DOWN, TAB, etc. ... basically to maybe run a macro to replay certain predefined keystrokes.

Is this possible in C#?

Your expert comments are eagerly awaited.

Thks

Arjay
August 11th, 2008, 02:18 PM
It is possible; however, if you don't own the webpage, it can be unreliable (because the owners of the webpage can change the content and break the macro).

wisebulls
August 11th, 2008, 08:03 PM
Thanks Arjay.

I agree it is not the ideal way to do it .... but operationally passing the values to the webpage is not working. Hence the macro concept.

Any leads on how to actually get this coded?

Arjay
August 11th, 2008, 08:37 PM
If you have a relationship with the webpage authors, the simplest way would be to get them to fix the issue (or let you know the proper parameters).

Doing this automatically can be done leveraging UI Automation and Active Accessibility (http://msdn.microsoft.com/en-us/library/ms788733.aspx).

I must warn you: Active Accessibility has a fairly steep learning curve.

wisebulls
August 11th, 2008, 11:43 PM
Thanks Arjay.

Unfortunately the website is a third party website and hence I am not able to make much progress on that front.

Will try and learn about UI automation and see if I can work out something simple for this.

If you can help in guiding me, it would be great.

My actual requirement has been posted under http://www.codeguru.com/forum/showthread.php?t=458899

where I have an attachment detailing my requirement.

If you can suggest any alternatives, I am eager to hear them.

Thanks once again for your response.

Arjay
August 12th, 2008, 12:25 AM
Read up on the UI Automation and Active Accessibility (AA) link I sent you.

You'll also want to download the Active Accessibility 2.0 SDK Tools (http://www.microsoft.com/downloads/details.aspx?familyid=3755582A-A707-460A-BF21-1373316E13F0&displaylang=en).

The tools include a AccExplorer tool which is the Active Accessibility equivalent of Spy++.

The reason I suggest using AA is because an html control doesn't show up as a regular Windows window (just like individual items in a tree or list control do not as well). Active Accessibility (AA) has the ability to manipulate these controls that don't show up as regular windows.

What you need to do is retrieve the parent AA hierarchy of the control that you wish to manipulate. You'll use the AccExplorer tool to retrieve this. You'll want to start at the control and record the AA hierarchy until you run into a 'real' window. Once you find a real window, you follow it's hierarchy until you reach the top level application window of the browser. This will be different for different browsers.

For example, if I want to log into hotmail. I need to first click on the hotmail link on http://www.msn.com before it takes me to the actual log on page.

In order to click on the link with AA, I need to grab it's hierarchy. So I use the AccExplorer32.exe tool:

http://www.msn.com/ Top level of AA hierarchy (this node has real window parent)
L MSN.com
L Hotmail Link we want to click on


Window hierarchy ( windows classes listed )
IEFrame
L TabWindowClass
L Shell DocObject View
L Internet Explorer_Server

So now that we have this information, we would use a combination of Windows api's such as EnumChildWindows and FindWindowEx to locate the top level window of IExplore and then walk the hierarchy down to locate the lowest window (class Internet Explorer_Server).

Once we have the lowest class, then we start using the Active Accessibility api's to walk the AA hierarchy until we reach the 'Hotmail' node.

From there we can use AA to click on the node.

We'd repeat the same process on the logon page to locate the email and password edit boxes and the submit button.

As I said, it's a bit of a learning curve.