Document
Assembly: ZennoLab.CommandCenter
Full name: ZennoLab.CommandCenter.Document
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
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
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
Gets the ID which represents document on the server.
It is used only for the technical purposes
ParentTab
Property
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Returns the html element located at specified coordinates.
Parameters
| Параметр | Описание |
|---|---|
x | The coordinate of x. |
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
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
| Параметр | Описание |
|---|---|
tags | Tags for search the element. If the count of tags is more than one then they are through ”;“. |
attrName | The attribute’s name. |
attrValue | The attribute’s value. |
searchKind | This parameter can take the following values: “text”, “notext” and “regexp”. |
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
Searches for all elements by the attribute.
Parameters
| Параметр | Описание |
|---|---|
tags | Tags for search the elements. If the number of tags is more than one then they are through ”;“. |
attrName | The attribute name. |
attrValue | The attribute value. |
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
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
| Параметр | Описание |
|---|---|
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
Searches for all elements by the ID.
Parameters
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
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
Searches for all elements by the name.
Parameters
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
tag | Tag for search the element. |
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
Searches for all elements by the tags.
Parameters
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
xpath | Tag for search the element. |
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
Searches for all elements by the xpath.
Parameters
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
selector | Css selector for search the element. |
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
Searches for all elements by the css selector.
Parameters
| Параметр | Описание |
|---|---|
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;GetChildren
Method
Returns the children of the document. (если рекурсивно, то всех детей, а если нет, то первый слой)
Parameters
| Параметр | Описание |
|---|---|
recursive |
Returns: The collection of html elements.
Example
GetFrames
Method
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
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
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
Executes a java script that is implemented by the currently loaded document.
Parameters
| Параметр | Описание |
|---|---|
script | A string expression with javascript. |
throwException | true if have to throw the JavaScript Evaluate exception; otherwise, false. The default value is false. |
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)");
}CreateElement
Method
Creates a new html element.
The IsNull property be true if the html element does not belongs to any document.
Parameters
| Параметр | Описание |
|---|---|
outerHtml | The dom text of the html element. |
Returns: A new html element.
Example
// navigate 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 main document
Document doc = tab.MainDocument;
// find element
HtmlElement he = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
// create a new html element
HtmlElement newHe = doc.CreateElement(he.OuterHtml);
// if element was created insert it to the document
if (!newHe.IsNull && !he.IsVoid) doc.InsertElement(newHe);Example2
// navigate 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 main document
$doc = $tab->MainDocument;
// find element
$he = $instance->GetTabByAddress("page")->GetDocumentByAddress("0")->FindElementByAttribute("input:checkbox", "fulltag", "input:checkbox", "text", 0);
// create a new html element
$newHe = $doc->CreateElement($he->OuterHtml);
// if element was created insert it to the document
if (!$newHe->IsNull && !$he->IsVoid) $doc->InsertElement($newHe);RemoveElement
Method
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
| Параметр | Описание |
|---|---|
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
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
| Параметр | Описание |
|---|---|
newElement | The html element to replace all occurrences of oldElement. |
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);ParseByXpath
Method
Parse page by XPath.
Parameters
| Параметр | Описание |
|---|---|
sourceType | Source type. Parse as DOM or Html. |
xpath | XPath. |
attribute | The attribute to take. |
onlyVisible | True if parse only visible elements; otherwise, false. Default value is true. |
Returns: The result of parsing data. Returns list of attributes.
Example
// get active tab
var tab = instance.ActiveTab;
if (tab.IsVoid || tab.IsNull) return -1;
// get document
var doc = tab.MainDocument;
//parse document
var resultParseByXpath = doc.ParseByXpath(ZennoLab.InterfacesLibrary.Enums.Parser.SourceType.Dom, "//body", "innerText");Example2
// get active tab
$tab = $instance->ActiveTab;
if (($tab->IsVoid) || ($tab->IsNull)) return -1;
// get document
$doc = $tab->MainDocument;
//parse document
$resultParseByXpath = $doc->ParseByXpath(ZennoLab\InterfacesLibrary\Enums\Parser\SourceType::Dom, "//body", "innerText");ParseByCssSelector
Method
Parse page by CSS-selector.
Parameters
| Параметр | Описание |
|---|---|
sourceType | Source type. Parse as DOM or Html. |
cssSelector | CSS-selector. |
attribute | The attribute to take. |
onlyVisible | True if parse only visible elements; otherwise, false. Default value is true. |
Returns: The result of parsing data. Returns list of attributes.
Example
// get active tab
var tab = instance.ActiveTab;
if (tab.IsVoid || tab.IsNull) return -1;
// get document
var doc = tab.MainDocument;
//parse document
var resultParseByXpath = doc.ParseByCssSelector(ZennoLab.InterfacesLibrary.Enums.Parser.SourceType.Dom, "//body", "innerText");Example2
// get active tab
$tab = $instance->ActiveTab;
if (($tab->IsVoid) || ($tab->IsNull)) return -1;
// get document
$doc = $tab->MainDocument;
//parse document
$resultParseByXpath = $doc->ParseByCssSelector(ZennoLab\InterfacesLibrary\Enums\Parser\SourceType::Dom, "//body", "innerText");GetNull
Method
Возвращает пустой документ