Document
Assembly: ZennoLab.CommandCenter
Full name: ZennoLab.CommandCenter.Document
Kind: class
Represents a document on a Web page. Contains the methods to search for html elements, gets or sets of values.
This class does not contain constructors.The documents is available only from the Tab object or the Instance object. The Document class contain the properties such as ErrorDetected, IsNull and IsVoid. Their use necessary for the correct work of your code.
Properties
IsVoid
Property
bool IsVoid { get; }
Gets the specified document is void or not.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// if document is void then exit
if (doc.IsVoid) return -1;
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// if document is void then exit
if ($doc->IsVoid) return -1;
return 0;
}ErrorDetected
Property
bool ErrorDetected { get; }
Gets information about the error detected in the performance last command.
If the Document object does not indicate to the real html document of dom model then this property is true. Also objects of this class contains IsNull and IsVoid properties for identification of documents’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 cookies
instance.ClearCookie();
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();
// get document
Document doc = tab.MainDocument;
// if error detected in document the exit
if (doc.ErrorDetected) return -1;
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$instance->ClearCookie();
$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();
// get document
$doc = $tab->MainDocument;
// if error detected in document the exit
if ($doc->ErrorDetected) return -1;
return 0;
}ZP_ID
Property
int ZP_ID { get; }
Gets the ID which represents document on the server.
It is used only for the technical purposes
ParentTab
Property
Tab ParentTab { get; }
Gets parent tab of the document.
Example
// get document
Document doc = tab.MainDocument;
// get parent tab of document
Tab pTab = doc.ParentTab;Example2
// get document
$doc = $tab->MainDocument;
// get parent tab of document
$pTab = $doc->ParentTab;ParentDocument
Property
Document ParentDocument { get; }
Gets parent document of the document.
Example
// get element
var el = tab.FindElementById("arrow");
// get parent document of document
var pDoc = el.ParentDocument.ParentDocument;Example2
// get element
$el = $tab->FindElementById("arrow");
// get parent tab of document
$pDoc = $el->ParentDocument->ParentDocument;Body
Property
HtmlElement Body { get; }
Gets the body of the document.
Example
// get document
Document doc = tab.MainDocument;
// get thew body of the main document
HtmlElement body = doc.Body;Example2
// get document
$doc = $tab->MainDocument;
// get thew body of the main document
$body = $doc->Body;Head
Property
HtmlElement Head { get; }
Gets the head element of the document.
Example
// get document
Document doc = tab.MainDocument;
// get head of document
HtmlElement head = doc.Head;Example2
// get document
$doc = $tab->MainDocument;
// get head of document
$head = $doc->Head;MainForm
Property
HtmlElement MainForm { get; }
Gets the first form the document.
Example
// get document
Document doc = tab.MainDocument;
// get the main form
HtmlElement mainForm = doc.MainForm;Example2
// get document
$doc = $tab->MainDocument;
// get the main form
$mainForm = $doc->MainForm;Forms
Property
HtmlElementCollection Forms { get; }
Gets all forms of the document.
Example
// get document
Document doc = tab.MainDocument;
// get collection of all forms
HtmlElementCollection heCol = doc.Forms;Example2
// get document
$doc = $tab->MainDocument;
// get collection of all forms
$heCol = $doc->Forms;FirstChild
Property
HtmlElement FirstChild { get; }
Gets the first child element of the document.
Example
// get document
Document doc = tab.MainDocument;
// get first child
HtmlElement he = doc.FirstChild;Example2
// get document
$doc = $tab->MainDocument;
// get first child
$he = $doc->FirstChild;URL
Property
string URL { get; }
Gets the URL of the document.
Example
// get document
Document doc = tab.MainDocument;
// get the url
string url = doc.URL;Example2
// get document
$doc = $tab->MainDocument;
// get the url
$url = $doc->URL;Domain
Property
string Domain { get; }
Gets the current domain of the document.
Example
// get document
Document doc = tab.MainDocument;
// get domain
string domain = doc.Domain;Example2
// get document
$doc = $tab->MainDocument;
// get domain
$domain = $doc->Domain;MainDomain
Property
string MainDomain { get; }
Gets the current main domain of the document.
Example
// get document
Document doc = tab.MainDocument;
// get the main domain
string domain = doc.MainDomain;Example2
// get document
$doc = $tab->MainDocument;
// get the main domain
$domain = $doc->MainDomain;Height
Property
int Height { get; }
Gets the height of the document.
Example
// get document
Document doc = tab.MainDocument;
// get the height of document
int height = doc.Height;Example2
// get document
$doc = $tab->MainDocument;
// get the height of document
$height = $doc->Height;Width
Property
int Width { get; }
Gets the width of the document.
Example
// get document
Document doc = tab.MainDocument;
// get width of the document
int width = doc.Width;Example2
$doc = $tab->MainDocument;
$width = $doc->Width;IsNull
Property
bool IsNull { get; }
Gets a value that indicates whether or not the value of the document is null value.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// if document is null then exit
if (doc.IsNull) return -1;
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// if document is null then exit
if ($doc->IsNull) return -1;
return 0;
}ReadyState
Property
string ReadyState { get; }
Gets the state of the document.
Example
// get document
Document doc = tab.MainDocument;
// get ReadyState of the document
if(doc.ReadyState != "complete") return -1;Example2
$doc = $tab->MainDocument;
if($doc->ReadyState != "complete") return -1;Referrer
Property
string Referrer { get; }
Gets the URI of the page that linked to this page.
Example
// get document
Document doc = tab.MainDocument;
// get Referrer of the document
var rUri = doc.Referrer;Example2
$doc = $tab->MainDocument;
$rUri = $doc->Referrer;DisplacementInTabWindow
Property
Point DisplacementInTabWindow { get; }
Gets the displacement of the upper left corner relative to the tab’s window.
Example
using System.Drawing;
...
// get document
Document doc = tab.MainDocument;
// get the displacement in tab for main document
Point point = doc.DisplacementInTabWindow;Example2
use System\Drawing;
...
// get document
$doc = $tab->MainDocument;
// get the displacement in tab for main document
$point = $doc->DisplacementInTabWindow;Methods
GetElementFromPoint
Method
HtmlElement GetElementFromPoint(int x, int y)
Returns the html element located at specified coordinates.
Parameters
| Type | Name | Description |
|---|---|---|
int | x | The coordinate of x. |
int | y | The coordinate of y. |
Returns: The element located at specified coordinates.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// get element from point
HtmlElement he = doc.GetElementFromPoint(50, 50);
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// get element from point
$he = $doc->GetElementFromPoint(50, 50);
return 0;
}FindElementByAttribute
Method
HtmlElement FindElementByAttribute(string tags, string attrName, string attrValue, string searchKind, int number)
Searches for an element by the attribute, and returns the first occurrence.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | tags | Tags for search the element. If the count of tags is more than one then they are through ”;“. |
string | attrName | The attribute’s name. |
string | attrValue | The attribute’s value. |
string | searchKind | This parameter can take the following values: “text”, “notext” and “regexp”. |
int | number | The item number in a collection of matching items. |
Returns: The first element that matches the conditions defined by the attribute, if found; otherwise, the result is void.
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 element using "text" parameter
HtmlElement he = tab.MainDocument.FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
if (he.IsVoid) return -1;
// set value
he.SetValue("True", instance.EmulationLevel, false);
// find element using "regexp" parameter
he = tab.MainDocument.FindElementByAttribute("input:radio", "fulltag", "input:radio", "regexp", 0);
if (he.IsVoid) return -1;
// set value
he.SetValue("0", instance.EmulationLevel, false);
// find element using "notext" parameter
he = tab.MainDocument.FindElementByAttribute("textarea", "top", "288", "notext", 0);
if (he.IsVoid) return -1;
// set value
he.SetValue("simple text", instance.EmulationLevel, false);
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 element using "text" parameter
$he = $tab->MainDocument->FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
if ($he->IsVoid) return -1;
// set value
$he->SetValue("True", $instance->EmulationLevel, false);
// find element using "regexp" parameter
$he = $tab->MainDocument->FindElementByAttribute("input:radio", "fulltag", "input:radio", "regexp", 0);
if ($he->IsVoid) return -1;
// set value
$he->SetValue("0", $instance->EmulationLevel, false);
// find element using "notext" parameter
$he = $tab->MainDocument->FindElementByAttribute("textarea", "top", "288", "notext", 0);
if ($he->IsVoid) return -1;
// set value
$he->SetValue("simple text", $instance->EmulationLevel, false);
return 0;
}FindElementsByAttribute
Method
HtmlElementCollection FindElementsByAttribute(string tags, string attrName, string attrValue, string searchKind)Searches for all elements by the attribute.
Parameters
| Type | Name | Description |
|---|---|---|
string | tags | Tags for search the elements. If the number of tags is more than one then they are through ”;“. |
string | attrName | The attribute name. |
string | attrValue | The attribute value. |
string | searchKind | This parameter can take the following values: “text”, “notext” and “regexp”. |
Returns: The collection of elements that matches the conditions defined by the attribute, if found; otherwise, the Count property is “0”.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element by attribute
HtmlElementCollection heCol = doc.FindElementsByAttribute("input:checkbox", "fulltag", "input:checkbox", "text");
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element by attribute
$heCol = $doc->FindElementsByAttribute("input:checkbox", "fulltag", "input:checkbox", "text");
return 0;
}FindElementById
Method
HtmlElement FindElementById(string id)Searches for an element by the ID, and returns the first occurrence.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | id | The ID that defines search condition of HTML elements. |
Returns: The first element that matches the conditions defined by the ID, if found; otherwise, the result is void.
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 html element by id
HtmlElement he = tab.MainDocument.FindElementById("overview");
if (he.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 html element by id
$he = $tab->MainDocument->FindElementById("overview");
if ($he->IsVoid) return -1;
return 0;
}FindElementsById
Method
HtmlElementCollection FindElementsById(string id)
Searches for all elements by the ID.
Parameters
| Type | Name | Description |
|---|---|---|
string | id | The ID that defines search condition of HTML elements. |
Returns: The collection of elements that matches the conditions defined by the ID, if found; otherwise, the Count property is “0”.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element by id
HtmlElementCollection heCol = doc.FindElementsById("overview");
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element by id
$heCol = $doc->FindElementsById("overview");
return 0;
}FindElementByName
Method
HtmlElement FindElementByName(string name)
Searches for an element by the name, and returns the first occurrence.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | name | The name that defines search condition of HTML elements. |
Returns: The first element that matches the conditions defined by the name, if found; otherwise, the result is void.
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 html element by name
HtmlElement he = tab.MainDocument.FindElementByName("text");
if (he.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 html element by name
$he = $tab->MainDocument->FindElementByName("text");
if ($he->IsVoid) return -1;
return 0;
}FindElementsByName
Method
HtmlElementCollection FindElementsByName(string name)
Searches for all elements by the name.
Parameters
| Type | Name | Description |
|---|---|---|
string | name | The name that defines search condition of HTML elements. |
Returns: The collection of elements that matches the conditions defined by the name, if found; otherwise, the Count property is “0”.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element by name
HtmlElementCollection heCol = doc.FindElementsByName("text");
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element by name
$heCol = $doc->FindElementsByName("text");
return 0;
}FindElementByTag
Method
HtmlElement FindElementByTag(string tag, int number)
Searches for an element by the tag.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | tag | Tag for search the element. |
int | number | The item number in a collection of matching items. |
Returns: The first element that matches the conditions defined by the tag, if found; otherwise, the result is void.
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 html element by tag
HtmlElement he = tab.MainDocument.FindElementByTag("input:checkbox", 0);
if (he.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 html element by tag
$he = $tab->MainDocument->FindElementByTag("input:checkbox", 0);
if ($he->IsVoid) return -1;
return 0;
}FindElementsByTags
Method
HtmlElementCollection FindElementsByTags(string tags)
Searches for all elements by the tags.
Parameters
| Type | Name | Description |
|---|---|---|
string | tags | Tags for search the elements. If the number of tags is more than one then they are through ”;“. |
Returns: The collection of elements that matches the conditions defined by the tags, if found; otherwise, the Count property is “0”.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element by tag
HtmlElementCollection heCol1 = doc.FindElementsByTags("input:checkbox");
// find element by tags
HtmlElementCollection heCol2 = doc.FindElementsByTags("input:checkbox;input:radio");
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element by tag
$heCol1 = $doc->FindElementsByTags("input:checkbox");
// find element by tags
$heCol2 = $doc->FindElementsByTags("input:checkbox;input:radio");
return 0;
}FindElementByXPath
Method
HtmlElement FindElementByXPath(string xpath, int number)
Searches for an element by the xpath.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | xpath | Tag for search the element. |
int | number | The item number in a collection of matching items. |
Returns: The first element that matches the conditions defined by the tag, if found; otherwise, the result is void.
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 html element by xpath
HtmlElement he = tab.MainDocument.FindElementByXPath("/html/body/div/div[@class]", 0);
if (he.IsVoid) return -2;
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 html element by xpath
$he = $tab->MainDocument->FindElementByXPath("/html/body/div/div[@class]", 0);
if ($he->IsVoid) return -2;
return 0;
}FindElementsByXPath
Method
HtmlElementCollection FindElementsByXPath(string xpath)
Searches for all elements by the xpath.
Parameters
| Type | Name | Description |
|---|---|---|
string | xpath | XPath for search the elements. |
Returns: The collection of elements that matches the conditions defined by the tags, if found; otherwise, the Count property is “0”.
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element by xpath
HtmlElementCollection heCol1 = doc.FindElementsByXPath("/html/body/div/div[@class]");
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element by xpath
$heCol1 = $doc->FindElementsByXPath("/html/body/div/div[@class]");
return 0;
}QuerySelector
Method
HtmlElement QuerySelector(string selector, int number)
Searches for an element by the css selector.
If html element was not found then this method returns the HtmlElement object in which IsVoid or IsNill property is “true”.
Parameters
| Type | Name | Description |
|---|---|---|
string | selector | Css selector for search the element. |
int | number | The item number in a collection of matching items. Default value is 0. |
Returns: The first element that matches the conditions defined by the tag, if found; otherwise, the result is void.
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 html element by css selector
var he = tab.MainDocument.QuerySelector(".inputs", 1);
if (he.IsVoid) return -2;
he.Click();QuerySelectorAll
Method
HtmlElementCollection QuerySelectorAll(string selector)
Searches for all elements by the css selector.
Parameters
| Type | Name | Description |
|---|---|---|
string | selector | Css selector for search the elements. |
Returns: The collection of elements that matches the conditions defined by the tags, if found; otherwise, the Count property is “0”.
Example
// clear cookies
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 css selector
var collection = tab.MainDocument.QuerySelectorAll(".inputs");
return collection.Count;GetFrames
Method
DocumentCollection GetFrames(bool recursive)
Returns the all frames.
For getting frames correctly needs full download of tab (web page). Use the IsBusy property and WaitDownloading method of Tab class for waiting for page’s downloading.
Parameters
| Type | Name | Description |
|---|---|---|
bool | recursive | true to return the all frames; otherwise, false. |
Returns: The collection of frames.
Example
// get document
Document doc = tab.MainDocument;
// get recursive all frames
DocumentCollection docCol1 = doc.GetFrames(true);
// get all frames from first level
DocumentCollection docCol2 = doc.GetFrames(false);Example2
// get document
$doc = $tab->MainDocument;
// get recursive all frames
$docCol1 = $doc->GetFrames(true);
// get all frames from first level
$docCol2 = $doc->GetFrames(false);GetPageText
Method
string GetPageText(bool recursive)
Gets the text of the document that the user sees
For getting page text correctly needs full download of tab (web page). Use the IsBusy property and WaitDownloading method of Tab class for waiting for page’s downloading.
Parameters
| Type | Name | Description |
|---|---|---|
bool | recursive | true to return text of the page and text of the subpage recorded through delimiters; otherwise, false. |
Returns: The text of the document.
Example
// get document
Document doc = tab.MainDocument;
// get recursive page text
string pagesText = doc.GetPageText(true);
// get page text from first level
string pageText = doc.GetPageText(false);Example2
// get document
$doc = $tab->MainDocument;
// get recursive page text
$pagesText = $doc->GetPageText(true);
// get page text from first level
$pageText = $doc->GetPageText(false);GetDomText
Method
string GetDomText(bool recursive)
Returns the dom text of the document.
For getting dom text correctly needs full download of tab (web page). Use the IsBusy property and WaitDownloading method of Tab class for waiting for page’s downloading.
Parameters
| Type | Name | Description |
|---|---|---|
bool | recursive | true to return dom text of the document and dom text of the sub-documents recorded through delimiters; otherwise, false. |
Returns: The dom text of the document
Example
// get document
Document doc = tab.MainDocument;
// get dom text include dom text of sub-documents
string domText1 = doc.GetDomText(true);
// get dom text without dom text of sub-documents
string domText2 = doc.GetDomText(false);Example2
// get document
$doc = $tab->MainDocument;
// get dom text include dom text of sub-documents
$domText1 = $doc->GetDomText(true);
// get dom text without dom text of sub-documents
$domText2 = $doc->GetDomText(false);EvaluateScript
Method
string EvaluateScript(string script, bool throwException, bool altWay)
Executes a java script that is implemented by the currently loaded document.
Parameters
| Type | Name | Description |
|---|---|---|
string | script | A string expression with javascript. |
bool | throwException | true if have to throw the JavaScript Evaluate exception; otherwise, false. The default value is false. |
bool | altWay | true if use alternative method of execution JavaScript code; otherwise, false. The default value is false. |
Returns: The result of the script execution.
Example
public static int Execute(Instance instance)
{
Tab tab = instance.MainTab;
if ((tab.IsVoid) || (tab.IsNull)) return -1;
if (tab.IsBusy) tab.WaitDownloading();
return tab.MainDocument.EvaluateScript("document.write(1)");
}Example2
public static function Execute($instance)
{
$tab = $instance->MainTab;
if (($tab->IsVoid) || ($tab->IsNull)) return -1;
if ($tab.IsBusy) $tab->WaitDownloading();
return $tab->MainDocument->EvaluateScript("document.write(1)");
}RemoveElement
Method
void RemoveElement(HtmlElement element)
Removes the first occurrence of a specific first level child html element from the document.
The IsNull property be true if the html element does not belongs to any document.
Parameters
| Type | Name | Description |
|---|---|---|
HtmlElement | element | The first level child html element to remove from the document. |
Example
public static int Execute(Instance instance, IZennoPosterProjectModel project)
{
// clear cookies
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();
// get document
Document doc = tab.MainDocument;
// find element for remove
HtmlElement he = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByTag("body", 0);
// if html element exist then remove it
if (!he.IsVoid) doc.RemoveElement(he);
return 0;
}Example2
public static function Execute($instance, $project)
{
// clear cookies
$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();
// get document
$doc = $tab->MainDocument;
// find element for remove
$he = $instance->GetTabByAddress("page")->GetDocumentByAddress("0")->FindElementByTag("body", 0);
// if html element exist then remove it
if (!$he->IsVoid) $doc->RemoveElement($he);
return 0;
}ReplaceElement
Method
void ReplaceElement(HtmlElement newElement, HtmlElement oldElement)
All occurrences of a specified html element in the current document replace with another specified html element.
The IsNull property be true if the html element does not belongs to any document.
Parameters
| Type | Name | Description |
|---|---|---|
HtmlElement | newElement | The html element to replace all occurrences of oldElement. |
HtmlElement | oldElement | The html element to be replaced. |
Example
// get document
Document doc = tab.MainDocument;
// find first element
HtmlElement he1 = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
// find second element
HtmlElement he2 = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByName("rad");
// if both elements are exist then replace he1 to he2
if (!he1.IsVoid && !he2.IsVoid) doc.ReplaceElement(he2, h1);Example2
// get document
$doc = $tab->MainDocument;
// find first element
$he1 = $instance->GetTabByAddress("page")->GetDocumentByAddress("0")->FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
// find second element
$he2 = $instance->GetTabByAddress("page")->GetDocumentByAddress("0")->FindElementByName("rad");
// if both elements are exist then replace he1 to he2
if (!$he1->IsVoid && !$he2->IsVoid) $doc->ReplaceElement($he2, $h1);