ZennoLab Assemblies Documentation
IndexOf Method (HtmlElementCollection)
Example 

Type: Zennolab.CommandCenter.HtmlElement

The document to locate in the HtmlElementCollection.

Searches for the specified object and returns the zero-based index of the first occurrence within the entire HtmlElementCollection.
Syntax
public int IndexOf( 
   HtmlElement element
)

Parameters

element

Type: Zennolab.CommandCenter.HtmlElement

The document to locate in the HtmlElementCollection.

Return Value

Type: System.Int32

The zero-based index of the first occurrence of item within the entire HtmlElementCollection, if found; otherwise, –1.

Exceptions
ExceptionDescription
ArgumentOutOfRangeExceptionindex is less than 0 or index is greater than Count.
Remarks
The HtmlElementCollection is searched forward starting at index and ending at the last element.
Example
The following code example demonstrates uses of the IndexOf method.
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
    // clear cookie
    instance.ClearCookie();
    
    // go to lessons.zennolab.com
    Tab tab = instance.MainTab;
    if ((tab.IsVoid) || (tab.IsNull)) return -1;
    if (tab.IsBusy) tab.WaitDownloading();
    tab.Navigate("lessons.zennolab.com");
    if (tab.IsBusy) tab.WaitDownloading();
    
    // find elements by tag
    HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
    
    // get last element
    HtmlElement he = heCol.Elements[heCol.Count-1];
    
    // get index of 'he' in collection
    int index = heCol.IndexOf(he);
    
    return 0;
}
public static function Execute($instance, $project)
{
    // clear cookie
    $instance->ClearCookie();
    
    // go to lessons.zennolab.com
    $tab = $instance->MainTab;
    if (($tab->IsVoid) || ($tab->IsNull)) return -1;
    if ($tab->IsBusy) $tab->WaitDownloading();
    $tab->Navigate("lessons.zennolab.com");
    if ($tab->IsBusy) $tab->WaitDownloading();
    
    // find elements by tag
    $heCol = $tab->FindElementsByTags("input:checkbox");
    
    // get last element
    $he = $heCol->Elements[$heCol->Count-1];
    
    // get index of 'he' in collection
    $index = $heCol->IndexOf($he);
    
    return 0;
}
Requirements

Target Platforms: Desktop: Windows XP SP3 and older. Server: Windows Server 2003 and older.

See Also

Reference

HtmlElementCollection Class
HtmlElementCollection Members
Elements Property
Count Property
GetByNumber Method

Send Feedback