Gaining access to properties of elements on a web page

J

jbonifacejr

Hello everyone. Very sorry if I am posting in the wrong place.

I am writing a test harnes that will be required to interact with
elements on a web page, such as inserting text in a text box. At some
step in the test I will have to identify the text box using properties
such as the name or id (which can both be set as attributes) or by the
innerhtml or outerhtml of the element if the other two "attributes"are
not set.

What generally happens is that I grab a collection of all of the
elements on the page that correspond to a specific type. Then I will
need to step through each element in the collection and compare its
properties to predetermined values that are stored in name/value pairs
in a StringDictionary. The problem is that I do not always know which
properties I will be comparing. They are different from case to case.
I don't see a method for an HTMLAnchorElement or HTMLImgElement
like .getProperties or anything like that. I do see the individual
things like .innerHTML, .src, etc.

When an elements properties do not match what I want, I remove it from
the collection. In the end, I expect to have in my collection one or
more elements that match what I want to click on or enter text in,
etc.

Does anyone have any suggestions on how I can compare properties of
elements in the collection to the name/value pairs in my
StringDictionary, especially when there are multiple name/value pairs.
 
N

Nicholas Paldino [.NET/C# MVP]

It sounds like you are using MSHTML through interop and that you have
access to the class, but not the interface. Have you tried casting to
IHTMLImgElement, etc, etc? That will expose the properties that you are
looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top