views:

48

answers:

1

I'm researching what options I have to access a browser's edit fields from outside. (Accessing the edit fields in an HTML page from an external application.)

I've played around with the Accessibility.IAccessible interface. That allows me to retrieve the plain text, which is great. But I would also like to modify the text in it, and the only option there is to write back all the plain text in one go. This means that any formatting in the edit field is lost, which is not-so-great (for me).

What I'd really like is some way to say "replace the text at pos 13 and 5 chars forward with the string XYZ" - just as I currently can do with regular RTF Text Boxes.

I've browsed the UI Automation interface, but while I found extensive support for retrieving text and text selections, I haven't yet found a way to do what I just described.

Any thought on this is greatly appreciated! Ekeforshus

A: 

I haven't done exactly what you require before, however it's useful to note that the older IAccessible interface doesn't have the fine grain control over textboxes that UI Automation does. So I would most certainly recommend going down that route.

I assume you've looked at the TextPattern? You can use this to walk through the textbox in various increments, and get formatting information about the text at a given point. I'm not sure if it will tell you the position of the character per say, but you could just walk through, character by character, until you reach the particular index, and then start deleteing/inserting/whatever.

It's also worth checking out UIAVerify (UIAutomationVerify.codeplex.com) which makes coding this kind of thing a bit simpler (not sure about text boxes specifically).

Saqib