Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mshtml Web Automation

Status
Not open for further replies.

jasonmarsh

Programmer
Aug 31, 2005
5
US
Hello... new to the forum here.

I have a abscure question that you probably don't run across every day.

I'm currently working on an object that will automatin web-based applications using the mshtml object. I can send text to input fields, I can click buttons, select hyperlinks, and various other actions.

However, I'm a little stumped with regard to a form list box. I am wanting to find all options within the list box. So, given an list box named DPF0, I want to return an array list of all the items within it (for only that control). I thought I would need to do this similar to how I loop through all the anchor on the page to get the hyperlinks. This may still be the correct option but the mshtml object is so vast and undocumented I am at a lost.

Here is what I am trying

ArrayList TempList = new ArrayList();

IHTMLElementCollection ListItems =(IHTMLElementCollection) Doc.getElementsByTagName("option");

foreach (HTMLOListElementClass ListItem in ListItems)
{
TempList.Add(ListItem.innerText);
}

This isn't working because of an invalid cast type on the HTMLOListElementClass.

Also this wouldn't work because it would return all option tag items, not just those specific to that DPF0 control.

Any help on this would be greatly appreciated. Also, if you have any help on selecting the item from the list box control, I could use that too.

Thank you in advance ~ Jason
 
Okay... a little more time and I figured it out.

For other developers... here is the code (without any error handling).

public ArrayList DropDownList ( string DropDownName )
{
Doc = (HTMLDocument) wb.Document;
ArrayList TempList = new ArrayList();

IHTMLElementCollection Elements = (IHTMLElementCollection) Doc.getElementsByTagName("select");

foreach (IHTMLElement Element in Elements)
{
IHTMLElementCollection ListItems = (IHTMLElementCollection) Element.children;

if (Element.getAttribute("name", 0).ToString() == DropDownName)
{
foreach (IHTMLElement ListItem in ListItems)
{
TempList.Add(ListItem.innerText);
}
}
}

return TempList;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top