HtmlElementCollection

Assembly: ZennoLab.CommandCenter
Full name: ZennoLab.CommandCenter.HtmlElementCollection
Kind: class


Represents a strongly typed list of html elements that can be accessed by index.

The HtmlElementCollection class contain the properties such as ErrorDetected and IsVoid. Their use necessary for the correct work of your code.

Properties

IsVoid

Property

bool IsVoid { get; }

Gets the specified collection is void collection or not.

Example

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");
                
                // if collection is void then return -1
                if (heCol.IsVoid) return -1;
                
                return 0;
            }

Example2

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");
                
                // if collection is void then return -1
                if ($heCol->IsVoid) return -1;
                
                return 0;
            }

ErrorDetected

Property

bool ErrorDetected { get; }

Gets information about the error detected in the performance last command

If the HtmlElementCollection object does not indicate to the real html element collection then this property is true. Also objects of this class contains IsVoid property for identification of html element collection’s existence. Almost all classes of ZennoLab.CommandCenter contains such properties. Use it for the correct execution of the code.

Example

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");
                
                // if error detected then return -1
                if (heCol.ErrorDetected) return -1;
                
                return 0;
            }

Example2

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");
                
                // if error detected then return -1
                if ($heCol->ErrorDetected) return -1;
                
                return 0;
            }

Count

Property

int Count { get; }

Gets the number of elements actually contained in the HtmlElementCollection.

The Count property it is the number of elements that are actually in the HtmlElementCollection.

Example

// find elements by tag
            HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
             
            // get count of collection
            int count = heCol.Count;

Example2

// find elements by tag
            $heCol = $tab->FindElementsByTags("input:checkbox");
             
            // get count of collection
            $count = $heCol->Count;

Elements

Property

HtmlElement[] Elements { get; }

Get copies the html elements of the HtmlElementCollection to a new array.

Example

// 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 an array of elements
            HtmlElement[] he = heCol.Elements;

Example2

// 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 an array of elements
            $he = $heCol->Elements;

Current

Property

HtmlElement Current { get; }

Gets the element in the collection at the current position of the enumerator.

Methods

GetByNumber

Method

HtmlElement GetByNumber(int number)

Gets the html element by specified number.

Parameters

TypeNameDescription
intnumberThe zero-based number of the html element to get.

Returns: The html element at the specified number.

Example

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");
                
                // if any element was not found
                if (heCol.Count == 0) return -1;
                
                // get last element by index (number)
                HtmlElement he = heCol.GetByNumber(heCol.Count-1);
                
                return 0;
            }

Example2

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");
                
                // if any element was not found
                if ($heCol->Count == 0) return -1;
                
                // get last element by index (number)
                $he = $heCol->GetByNumber($heCol->Count-1);
                
                return 0;
            }

Add

Method

void Add(HtmlElement element)

Adds a html element to the end of the HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElementelementThe html element to be added to the end of the HtmlElementCollection.

Example

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 elments by tag
                HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
                
                // find elements by tag
                HtmlElementCollection newHeCol = tab.FindElementsByTags("input:radio");
                
                // add all elements from second to first collection
                for (int i = 0; i < newHeCol.Count; i++) heCol.Add(newHeCol.Elements[i]);
                
                return 0;
            }

Example2

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 elments by tag
                $heCol = $tab->FindElementsByTags("input:checkbox");
                
                // find elements by tag
                $newHeCol = $tab->FindElementsByTags("input:radio");
                
                // add all elements from second to first collection
                for ($i = 0; $i < $newHeCol->Count; $i++) $heCol->Add($newHeCol->Elements[$i]);
                
                return 0;
            }

AddRange

Method

void AddRange(HtmlElementCollection elements)

Adds the html elements of the specified collection to the end of the HtmlElementCollection.

The order of the elements in the collection is preserved in the HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElementCollectionelementsThe collection whose html elements should be added to the end of the HtmlElementCollection. The collection itself cannot be null.

Example

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");
                
                // find elements by tag
                HtmlElementCollection newHeCol = tab.FindElementsByTags("input:radio");
                
                // add second collection to first
                heCol.AddRange(newHeCol);
                
                return 0;
            }

Example2

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");
                
                // find elements by tag
                $newHeCol = $tab->FindElementsByTags("input:radio");
                
                // add second collection to first
                $heCol->AddRange($newHeCol);
                
                return 0;
            }

AddRange

Method

void AddRange(HtmlElement[] elements)

Adds the htm elements of the specified array to the end of the HtmlElementCollection.

The order of the elements in the collection is preserved in the HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElement[]elementsThe array whose html elements should be added to the end of the HtmlElementCollection. The collection itself cannot be null.

Example

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");
                
                // find elements by tag
                HtmlElementCollection newHeCol = tab.FindElementsByTags("input:radio");
                
                // add second collection to first
                heCol.AddRange(newHeCol.Elements);
                
                return 0;
            }

Example2

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");
                
                // find elements by tag
                $newHeCol = $tab->FindElementsByTags("input:radio");
                
                // add second collection to first
                $heCol->AddRange($newHeCol);
                
                return 0;
            }

Insert

Method

void Insert(HtmlElement element, int index)

Inserts a html element into the HtmlElementCollection at the specified index.

If index is equal to Count, item is added to the end of HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElementelementThe document to insert.
intindexThe zero-based index at which html element should be inserted.

Example

// find elements by tag
            HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
             
            // find element by name
            HtmlElement he = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByName("rad");
             
            // if collection is invalid then return -1
            if ((heCol.IsVoid) || (heCol.ErrorDetected)) return -1;
             
            // insert element to collection
            heCol.Insert(he, 0);

Example2

// find elements by tag
            $heCol = $tab->FindElementsByTags("input:checkbox");
             
            // find element by name
            $he = $instance->GetTabByAddress("page")->GetDocumentByAddress("0")->FindElementByName("rad");
             
            // if collection is invalid then return -1
            if (($heCol->IsVoid) || ($heCol->ErrorDetected)) return -1;
             
            // insert element to collection
            $heCol->Insert($he, 0);

InsertRange

Method

void InsertRange(HtmlElementCollection elements, int index)

Inserts the html element of a collection into the HtmlElementCollection at the specified index.

If index is equal to Count, the elements are added to the end of HtmlElementCollection. The order of the elements in the collection is preserved in the HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElementCollectionelementsThe collection whose elements should be inserted into the HtmlElementCollection. The collection itself cannot be null.
intindexThe zero-based index at which the new html elements should be inserted.

Example

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");
                if ((heCol.IsVoid) || (heCol.ErrorDetected)) return -1;
                
                // find elements by tag
                HtmlElementCollection newHeCol = tab.FindElementsByTags("input:radio");
                if ((newHeCol.IsVoid) || (newHeCol.ErrorDetected)) return -1;
                
                // insert second collection to first
                heCol.InsertRange(newHeCol, 0);
                
                return 0;
            }

Example2

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");
                if (($heCol->IsVoid) || ($heCol->ErrorDetected)) return -1;
                
                // find elements by tag
                $newHeCol = $tab->FindElementsByTags("input:radio");
                if (($newHeCol->IsVoid) || ($newHeCol->ErrorDetected)) return -1;
                
                // insert second collection to first
                $heCol->InsertRange($newHeCol, 0);
                
                return 0;
            }

InsertRange

Method

void InsertRange(HtmlElement[] elements, int index)

Inserts the html element of an array into the HtmlElementCollection at the specified index.

If index is equal to Count, the elements are added to the end of HtmlElementCollection. The order of the elements in the collection is preserved in the HtmlElementCollection.

Parameters

TypeNameDescription
HtmlElement[]elementsThe array whose elements should be inserted into the HtmlElementCollection. The array itself cannot be null.
intindexThe zero-based index at which the new html element should be inserted.

Example

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");
                if ((heCol.IsVoid) || (heCol.ErrorDetected)) return -1;
                
                // find elements by tag
                HtmlElementCollection newHeCol = tab.FindElementsByTags("input:radio");
                if ((newHeCol.IsVoid) || (newHeCol.ErrorDetected)) return -1;
                
                // insert second collection to first
                heCol.InsertRange(newHeCol.Elements, 0);
                
                return 0;
            }

Example2

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");
                if (($heCol->IsVoid) || ($heCol->ErrorDetected)) return -1;
                
                // find elements by tag
                $newHeCol = $tab->FindElementsByTags("input:radio");
                if (($newHeCol->IsVoid) || ($newHeCol->ErrorDetected)) return -1;
                
                // insert second collection to first
                $heCol->InsertRange($newHeCol->Elements, 0);
                
                return 0;
            }

Remove

Method

void Remove(int index)

Removes the element at the specified index of the HtmlElementCollection.

Parameters

TypeNameDescription
intindexThe zero-based index of the html element to remove.

Example

// find elements by tag
            HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
             
            // remove last element
            heCol.Remove(heCol.Count-1);

Example2

// find elements by tag
            $heCol = $tab->FindElementsByTags("input:checkbox");
             
            // remove last element
            $heCol->Remove($heCol->Count-1);

IndexOf

Method

int IndexOf(HtmlElement element)

Searches for the specified object and returns the zero-based index of the first occurrence within the entire HtmlElementCollection.

The HtmlElementCollection is searched forward starting at index and ending at the last element.

Parameters

TypeNameDescription
HtmlElementelementThe document to locate in the HtmlElementCollection.

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

Example

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;
            }

Example2

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;
            }

AttributesToString

Method

string AttributesToString(string attrName)

Returns the attributes of all elements of the collection with the given name and assembles them into text. The attributes recorded through a line terminator.

Parameters

TypeNameDescription
stringattrNameAttribute name.

Returns: Attributes of all elements of the collection with the given name in text form.

Example

// find elements by tag
            HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
             
            // get attributes to string
            string result = heCol.AttributesToString("FullTagName");

Example2

// find elements by tag
            $heCol = $tab->FindElementsByTags("input:checkbox");
             
            // get attributes to string
            $result = $heCol->AttributesToString("FullTagName");

AttributesToString

Method

string AttributesToString(string attrName, string delemiter)

Returns the attributes of all elements of the collection with the given name and assembles them into text. The attributes recorded through the specified delimiter.

Parameters

TypeNameDescription
stringattrNameAttribute name.
stringdelemiterDelimiter that separates attributes in the text.

Returns: Attributes of all elements of the collection with the given name in text form

Example

// find elements by tag
            HtmlElementCollection heCol = tab.FindElementsByTags("input:checkbox");
             
            // get attributes to string
            string result = heCol.AttributesToString("FullTagName", ":");

Example2

// find elements by tag
            $heCol = $tab->FindElementsByTags("input:checkbox");
             
            // get attributes to string
            $result = $heCol->AttributesToString("FullTagName", ":");

GetEnumerator

Method

IEnumerator<HtmlElement> GetEnumerator()

Returns an enumerator that iterates through a collection.

Returns: An IEnumerator object that can be used to iterate through the collection.

Dispose

Method

void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

MoveNext

Method

bool MoveNext()

Advances the enumerator to the next element of the collection.

Reset

Method

void Reset()

Sets the enumerator to its initial position, which is before the first element in the collection.