9Hits Macros Build-in Functions#
Note
Some functions are required await keyword
TheCampaign object#
You can get some informations of your campaign from TheCampaign object. This object is available on the Exchange Mode only.
Log#
Print one or more message to the Macros Editor output.
Parameters
| Name | Description |
|---|---|
msg1 |
Message to show on the Output tab on the Macros Editor |
... |
Message to show on the Output tab on the Macros Editor |
msg_n |
Message to show on the Output tab on the Macros Editor |
Delay#
Pause the script for a period of time in milliseconds.
Parameters
| Name | Description |
|---|---|
ms |
Delay time in miliseconds. |
ms2 |
Delay in the range from ms to ms2 (optional). |
Example
Random#
Returns a random integer that is within a specified range.
Parameters
| Name | Description |
|---|---|
num1 |
Random a number from 0 to num1. |
num2 |
Random a number between num1 and num2 (optional). |
Example
RandomArray#
Take a random item from an array.
Parameters
| Name | Description |
|---|---|
array |
An array of any element |
Example
ClickByCoordinates#
Click on an area on your website based on coordinates.
Parameters
| Name | Description |
|---|---|
x1 |
x coordinate of the top-left |
y1 |
y coordinate of the top-left |
x2 |
x coordinate of the right-bottom |
y2 |
y coordinate of the right-bottom |
nClick |
Click count, default is 1 |

Example
ClickBySelector#
Click on an element based on a css selector.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
index |
Index of the element in case there are more than one elements matched the selector. You can use number (0 for the first element) or "random" to randomly click an element, default is 0. |
nClick |
Click count, default is 1 |
frameSearch |
If the target element is in an iframe, you have to tell the macros what frame is, empty mean top main frame. |
frameSearchType |
Frame search conditions, possible value: "src-starts", "src-ends", "src-equals", "src-contains", "src-regex", "frame-path", default is "src-contains". |
Example
Tip
Are you confused? Don't worry! You can also generate this click command easily by using the Editor like this.

ClickById#
Click on an element based on its ID.
Parameters
| Name | Description |
|---|---|
id |
ID of the element. |
nClick |
Click count, default is 1 |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickByXpath#
Click on an element based on its xpath.
Parameters
| Name | Description |
|---|---|
xpath |
xpath of the element. You may use the GenerateXpath function to generate xpath. |
nClick |
Click count, default is 1 |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickByTag#
Click on an element based on its tag name.
Parameters
| Name | Description |
|---|---|
tag |
Tag name of the element. |
index |
Index of the element in case there are more than one elements has the same tag name. You can use number (0 for the first element) or "random" to randomly click an element, default is 0. |
nClick |
Click count, default is 1 |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickByClass#
Click on an element based on its class name.
Parameters
| Name | Description |
|---|---|
class |
Class name of the element. |
index |
Index of the element in case there are more than one elements has the same class name. You can use number (0 for the first element) or "random" to randomly click an element, default is 0. |
nClick |
Click count, default is 1 |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickRandomLink#
Randomly click any link on your website.
Parameters
| Name | Description |
|---|---|
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickRandomInternalLink#
Randomly click any internal link on your website.
Parameters
| Name | Description |
|---|---|
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
ClickRandomExternalLink#
Randomly click any external link on your website.
Parameters
| Name | Description |
|---|---|
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
SetById#
Set the value for an attribute of an element based on its ID.
Parameters
| Name | Description |
|---|---|
id |
ID of the element. |
attr |
The attribute you want to set. |
value |
The value you want to set. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
|
SetByXpath#
Set the value for an attribute of an element based on its xpath.
Parameters
| Name | Description |
|---|---|
xpath |
Xpath of the element. |
attr |
The attribute you want to set. |
value |
The value you want to set. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
|
SetByClass#
Set the value for an attribute of an element based on its class name.
Parameters
| Name | Description |
|---|---|
class |
Class name of the element. |
attr |
The attribute you want to set. |
value |
The value you want to set. |
index |
Index of the element in case there are multiple elements with the same class name. 0 is the first element, you can also use "random" or "all". |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
SetByTag#
Set the value for an attribute of an element based on its tag name.
Parameters
| Name | Description |
|---|---|
tag |
Tag name of the element. |
attr |
The attribute you want to set. |
value |
The value you want to set. |
index |
Index of the element in case there are multiple elements with the same tag name. 0 is the first element, you can also use "random" or "all". |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
CapturePage#
Take an screenshot of the web page in JPEG format, return it as base64 encoded.
Parameters
| Name | Description |
|---|---|
quality |
The quality of the image (from 0 to 100), default is 80. |
CaptureArea#
Capture a specified area of the web page with JPEG format, return as base64 encoded.
Parameters
| Name | Description |
|---|---|
x1 |
x coordinate of the top-left |
y1 |
y coordinate of the top-left |
x2 |
x coordinate of the right-bottom |
y2 |
y coordinate of the right-bottom |
quality |
The quality of the image (from 0 to 100), default is 80. |
Example
CaptureElement#
Capture an element by a selector of the web page with JPEG format, return as base64 encoded. Useful when you need to take a picture to bypass captcha, but you can also capture any element not just img tag.
Parameters
| Name | Description |
|---|---|
selector |
The CSS selector |
quality |
The quality of the image (from 0 to 100), default is 80. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
EvalScript#
Execute javascript code on the website and return value.
Parameters
| Name | Description |
|---|---|
jsCode |
The javascript code to execute. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
GenerateXpath#
Create xpath to target the element. You can combine this function with ClickByXpath, SetByXpath or any function that use xpath.
Parameters
| Name | Description |
|---|---|
tag |
Tag name of the element. |
attr |
The attribute of the element. |
value |
The value of the attr. |
index |
The index of the element. |
Example
GetAttribute#
Get the value of an attribute of an element based on its xpath.
Parameters
| Name | Description |
|---|---|
xpath |
Xpath of the element. |
attr |
The attribute of the element. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
GetElementPos#
Get the coordinates of an element.
Parameters
| Name | Description |
|---|---|
jsCode |
The javascript code to locate the element. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
GetBrowserSize#
Return the browser size.
GetSource#
Return the source code of the website.
Example
GetHtml#
Return the renderrerd html code of the website.
Example
GetUrl#
Return the current URL.
Example
GetUserAgent#
Return the current User-Agent.
Example
IsLoading#
Indicates that the browser is loading or not.
IsMobile#
Indicates that the browser is mobile or not (base on the User-Agent).
Example
IsHideBrowser#
Indicates the browser visibility.
Example
WaitForLoading#
Wait until the browser has finished loading (main and all sub frame), return true if browser is fully loaded, false if timedout (if timeout is passed).
Parameters
| Name | Description |
|---|---|
timeout |
In seconds, 0 mean unlimited. |
Navigate#
Navigate to an url.
Parameters
| Name | Description |
|---|---|
url |
The target URL. |
referrer |
Spoof a referrer url. |
Example
GetDuration#
Exchange Mode only
Returns the maximum duration in seconds that the app will view your website.
GetViewedDuration#
Exchange Mode only
Returns the total time in seconds that the app viewed your website.
GetMaxPopups#
Exchange Mode only
Returns the maximum number of popups your site may be allowed to open, if the owner disabled popups, the return value will be 0.
GetConnectionType#
Exchange Mode only
Returns the connection type of the app. Possible values are: system, http, socks4, socks5, ssh.
GetImageByXpath#
Get an image in base64 format based on its xpath.
Parameters
| Name | Description |
|---|---|
xpath |
xpath of the element. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
SolveRecaptcha#
This is a high-level function for solving ReCaptcha, built on top of functions _2CaptchaSolve and ACSolve. If the captcha is successfully solved, the result will automatically be assigned, then you can click the buttons such as Submit, Continue, etc using click functions. If these buttons do not exist, you can call the function TryToCallRecaptchaCallBack instead. The return result will be false in case of failed resolve, otherwise the data from the service API server.
Parameters
| Name | Description |
|---|---|
service |
Can be: 2captcha or anti-captcha |
apiKey |
Your API key with the corresponding service |
timeout |
Maximum time to solve the captcha, in seconds (optional) |
overrideApiServer |
Overwrite the URL server of the captcha service (optional) |
Example
SolvehCaptcha#
This is a high-level function for solving hCaptcha, built on top of functions _2CaptchaSolve and ACSolve. If the captcha is successfully solved, the result will automatically be assigned, then you can click the buttons such as Submit, Continue, etc using click functions. The return result will be false in case of failed resolve, otherwise the data from the service API server.
Parameters
| Name | Description |
|---|---|
service |
Can be: 2captcha or anti-captcha |
apiKey |
Your API key with the corresponding service |
timeout |
Maximum time to solve the captcha, in seconds (optional) |
overrideApiServer |
Overwrite the URL server of the captcha service (optional) |
Example
SolveImageCaptcha#
This is a high-level function for solving image captcha, built on top of functions _2CaptchaSolve and ACSolve. If the captcha is successfully solved, the result will automatically be assigned, then you can click the buttons such as Submit, Continue, etc using click functions.The return result will be false in case of failed resolve, otherwise the data from the service API server.
Syntax
Parameters
| Name | Description |
|---|---|
imgSelector |
The CSS selector of the image. |
resultSelector |
The CSS selector of the input textbox to fill the reuslt. |
service |
Can be: 2captcha or anti-captcha |
apiKey |
Your API key with the corresponding service |
timeout |
Maximum time to solve the captcha, in seconds (optional) |
overrideApiServer |
Overwrite the URL server of the captcha service (optional) |
Example
_2CaptchaSolve#
Solve captcha by 2Captcha service. If you want to use another provider that is similar with 2captcha, you can override the api endpoint by set a url to _2CaptchaServer.
Parameters
| Name | Description |
|---|---|
params |
2Captcha parameters. |
timeout |
Timeout in seconds. |
Example
_2CaptchaReportBad#
If you believe that captcha is resolved incorrectly, you can use this function to report it. However do not abuse.
Parameters
| Name | Description |
|---|---|
key |
Your 2Captcha API Key. |
captchaId |
ID of the captcha returned by the _2CaptchaSolve function. |
Example
ACSolve#
Solve captcha by anti-captcha service. If you want to use another provider that is similar with anti-captcha, you can override the api endpoint to AntiCaptchaServer.
Parameters
| Name | Description |
|---|---|
params |
anti-captcha parameters. |
timeout |
Timeout in seconds. |
Example
ACReportIncorrectImage#
If you believe that the image captcha is resolved incorrectly, you can use this function to report it. However do not abuse.
Parameters
| Name | Description |
|---|---|
key |
Your anti-captcha API Key. |
taskId |
The taskId returned by the ACSolve function. |
Example
ACReportIncorrectRecaptcha#
If you believe that the reCaptcha is resolved incorrectly, you can use this function to report it. However do not abuse.
Parameters
| Name | Description |
|---|---|
key |
Your anti-captcha API Key. |
taskId |
The taskId returned by the ACSolve function. |
Example
TryToCallRecaptchaCallBack#
Try to execute recaptcha callback.
Parameters
| Name | Description |
|---|---|
result |
The recaptcha response. |
Example
WaitForElement#
Wait for an element (a DOM object) until a certain condition is satisfied. Return true when conditionCallback function returns true, false when timed out.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
conditionCallback |
The callback function with an argument of the object selected by the selector must return true or false. |
timeout |
Maximum time to wait for the conditionCallback to returns true, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmToAppear#
Wait for an element to appear.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmToDisappear#
Wait for an element to disappear.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmToHasAttr#
Wait for an element until it has a desired attribute.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
attr |
The desired attribute |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmToHasAttrValue#
Wait for an element until it has a desired attribute with a desired value.
Syntax
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
attr |
The desired attribute |
value |
The desired value |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmToLoseAttr#
Wait for an element until it lose a desired attribute.
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
attr |
The desired attribute |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
WaitForElmTextUntil#
Wait for an element until its text (innerText) satisfies a certain condition.
Syntax
Parameters
| Name | Description |
|---|---|
selector |
a CSS selector |
condition |
Condition to check value, can be: equals, contains, starts-with, ends-with |
value |
The desired value |
timeout |
Maximum time to wait, in seconds, default is 300s |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
TabCount#
Returns the number of opening browser windows.
Example
Typing#
Simulate keyboard typing.
Parameters
| Name | Description |
|---|---|
text |
Text to type. |
speed1 - speed2 |
Delay time range to adjust typing speed (in miliseconds). |
ResizeTo#
Change the browser size.
Parameters
| Name | Description |
|---|---|
width |
New width. |
height |
New height. |
Example
ScrollTo#
Scroll the browser to the specified coordinates.
Parameters
| Name | Description |
|---|---|
x |
x coordinates. |
y |
y coordinates. |
smooth |
Smooth scrolling. |
TabFocus#
Focusing on the specified browser tab, macros will be executed on the focused tab after this function call.
Parameters
| Name | Description |
|---|---|
target |
Can be a tab index (1 is the first tab) or a search pattern by URL. |
Example
SendKeyPress#
Simulate keypress event.
Parameters
| Name | Description |
|---|---|
keyCode |
Key Code |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT |
Example
SendKeyDown#
Simulate keydown event.
Parameters
| Name | Description |
|---|---|
keyCode |
Key Code |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT |
Example
SendKeyUp#
Simulate keyup event.
Parameters
| Name | Description |
|---|---|
keyCode |
Key Code |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT |
Example
SendKeyChar#
Simulate keychar event.
Parameters
| Name | Description |
|---|---|
keyCode |
Key Code or a character |
SendMouseClick#
Simulate mouseclick event.
Parameters
| Name | Description |
|---|---|
x |
x coordinates. |
y |
y coordinates. |
button |
Can be "left", "right" or "middle". |
Example
SendMouseMove#
Simulate mousemove event.
Parameters
| Name | Description |
|---|---|
x |
x coordinates. |
y |
y coordinates. |
Example
SendMouseWheel#
Simulate mousewheel event.
Parameters
| Name | Description |
|---|---|
deltaX |
Delta X. |
deltaY |
Delta Y. |
Example
Exit#
Close all browsers immediately.
HttpRequest#
Make HTTP Request
Parameters
| Name | Description |
|---|---|
url |
URL to send request. |
params |
Post Parameters. |
referrer |
Referrer URL. |
headers |
Custom HTTP headers. |
Example
ReadFile#
Bot and Profile Mode only
Read and return the contents of a file as text.
Parameters
| Name | Description |
|---|---|
path |
Path to file. |
WriteFile#
Bot and Profile Mode only
Write text to a file.
Parameters
| Name | Description |
|---|---|
path |
Path to file. |
content |
Text content. |
mode |
Can be "override" or "append". |
Example
GetDownloadedFiles#
Bot and Profile Mode only
Returns an array of downloaded filenames.
Example
IsFileDownloaded#
Bot and Profile Mode only
Check if the given file has been downloaded.
Parameters
| Name | Description |
|---|---|
fileName |
Name of the file to check. |
Example
SetUploadFileOrFolder#
Bot and Profile Mode only
Set the files will be selected when you click to a Chose File button on a web-page..
Parameters
| Name | Description |
|---|---|
paths |
a path to file/folder or an array of paths. |
Example
GetCurrentDir#
Bot and Profile Mode only
Returns the current path that 9Hits App is running.
Example
Tip
Feel free to request a new function here.
Keycode Table#
Use for these functions: SendKeyPress, SendKeyDown, SendKeyUp, SendKeyChar.
Click here to see the list of key codes
| Name | Description |
|---|---|
K_BACKSPACE |
Backspace |
K_TAB |
Tab |
K_ENTER |
Enter |
K_SHIFT |
Shift |
K_CONTROL |
Control |
K_ALT |
Alt |
K_PAUSE |
Pause |
K_CAPSLOCK |
CapsLock |
K_ESCAPE |
Escape |
K_SPACE |
Space |
K_PAGEUP |
PageUp |
K_PAGEDOWN |
PageDown |
K_END |
End |
K_HOME |
Home |
K_ARROWLEFT |
ArrowLeft |
K_ARROWUP |
ArrowUp |
K_ARROWRIGHT |
ArrowRight |
K_ARROWDOWN |
ArrowDown |
K_PRINTSCREEN |
PrintScreen |
K_INSERT |
Insert |
K_DELETE |
Delete |
K_DIGIT0 |
Digit0 (0) |
K_DIGIT1 |
Digit1 (1) |
K_DIGIT2 |
Digit2 (2) |
K_DIGIT3 |
Digit3 (3) |
K_DIGIT4 |
Digit4 (4) |
K_DIGIT5 |
Digit5 (5) |
K_DIGIT6 |
Digit6 (6) |
K_DIGIT7 |
Digit7 (7) |
K_DIGIT8 |
Digit8 (8) |
K_DIGIT9 |
Digit9 (9) |
K_KEYA |
KeyA (A) |
K_KEYB |
KeyB (B) |
K_KEYC |
KeyC (C) |
K_KEYD |
KeyD (D) |
K_KEYE |
KeyE (E) |
K_KEYF |
KeyF (F) |
K_KEYG |
KeyG (G) |
K_KEYH |
KeyH (H) |
K_KEYI |
KeyI (I) |
K_KEYJ |
KeyJ (J) |
K_KEYK |
KeyK (K) |
K_KEYL |
KeyL (L) |
K_KEYM |
KeyM (M) |
K_KEYN |
KeyN (N) |
K_KEYO |
KeyO (O) |
K_KEYP |
KeyP (P) |
K_KEYQ |
KeyQ (Q) |
K_KEYR |
KeyR (R) |
K_KEYS |
KeyS (S) |
K_KEYT |
KeyT (T) |
K_KEYU |
KeyU (U) |
K_KEYV |
KeyV (V) |
K_KEYW |
KeyW (W) |
K_KEYX |
KeyX (X) |
K_KEYY |
KeyY (Y) |
K_KEYZ |
KeyZ (Z) |
K_METALEFT |
MetaLeft (Meta) |
K_METARIGHT |
MetaRight (Meta) |
K_CONTEXTMENU |
ContextMenu |
K_NUMPAD0 |
Numpad0 (0) |
K_NUMPAD1 |
Numpad1 (1) |
K_NUMPAD2 |
Numpad2 (2) |
K_NUMPAD3 |
Numpad3 (3) |
K_NUMPAD4 |
Numpad4 (4) |
K_NUMPAD5 |
Numpad5 (5) |
K_NUMPAD6 |
Numpad6 (6) |
K_NUMPAD7 |
Numpad7 (7) |
K_NUMPAD8 |
Numpad8 (8) |
K_NUMPAD9 |
Numpad9 (9) |
K_NUMPADMULTIPLY |
NumpadMultiply (*) |
K_NUMPADADD |
NumpadAdd (+) |
K_NUMPADSUBTRACT |
NumpadSubtract (-) |
K_NUMPADDECIMAL |
NumpadDecimal (.) |
K_NUMPADDIVIDE |
NumpadDivide (/) |
K_F1 |
F1 |
K_F2 |
F2 |
K_F3 |
F3 |
K_F4 |
F4 |
K_F5 |
F5 |
K_F6 |
F6 |
K_F7 |
F7 |
K_F8 |
F8 |
K_F9 |
F9 |
K_F10 |
F10 |
K_F11 |
F11 |
K_F12 |
F12 |
K_NUMLOCK |
NumLock |
K_SCROLLLOCK |
ScrollLock |
K_AUDIOVOLUMEMUTE |
AudioVolumeMute |
K_AUDIOVOLUMEDOWN |
AudioVolumeDown |
K_AUDIOVOLUMEUP |
AudioVolumeUp |
K_MEDIATRACKNEXT |
MediaTrackNext |
K_MEDIATRACKPREVIOUS |
MediaTrackPrevious |
K_MEDIASTOP |
MediaStop |
K_MEDIAPLAYPAUSE |
MediaPlayPause |
K_LAUNCHMAIL |
LaunchMail |
K_LAUNCHMEDIAPLAYER |
LaunchMediaPlayer |
K_LAUNCHAPPLICATION1 |
LaunchApplication1 |
K_LAUNCHAPPLICATION2 |
LaunchApplication2 |
K_SEMICOLON |
Semicolon (;) |
K_EQUAL |
Equal (=) |
K_COMMA |
Comma (,) |
K_MINUS |
Minus (-) |
K_PERIOD |
Period (.) |
K_SLASH |
Slash (/) |
K_BACKQUOTE |
Backquote (`) |
K_BRACKETLEFT |
BracketLeft ([) |
K_BACKSLASH |
Backslash (\) |
K_BRACKETRIGHT |
BracketRight (]) |
K_QUOTE |
Quote (') |

