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.
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
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
MoveMouse#
Simulate moving the mouse between two points.
Parameters
| Name | Description |
|---|---|
startPoint |
Start point. |
endPoint |
End point. |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT. |
button |
Pressed mouse button: none, left, right, middle. |
Example
MoveMouseToArea#
Simulate moving the mouse to an area.
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 |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT. |
button |
Pressed mouse button: none, left, right, middle. |

Example
MoveMouseToAnyWhere#
Simulate moving the mouse to a random position.
Parameters
| Name | Description |
|---|---|
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT. |
button |
Pressed mouse button: none, left, right, middle. |
MoveMouseToElmBySelector#
Simulate moving the mouse to an element by a selector.
Syntax
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. |
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". |
modifiers |
Valid values: WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT. |
button |
Pressed mouse button: none, left, right, middle. |
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
Tip
You can also get the coordinates from the Editor like this
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
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 |
Typing#
Simulate keyboard typing.
Parameters
| Name | Description |
|---|---|
text |
Text to type. |
speed1 - speed2 |
Delay time range to adjust typing speed (in miliseconds). |
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. Please note returned data can only be primitive data types or simple objects.
Parameters
| Name | Description |
|---|---|
jsCode |
The javascript code to execute. |
frameSearch |
See ClickBySelector |
frameSearchType |
See ClickBySelector |
Example
EvalScriptWithPromise#
Same as EvalScript but execute a js code with an async function or a promise.
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
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.
GetWindowSize#
Return the window size.
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
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
TabCount#
Returns the number of opening browser windows.
Example
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
Exit#
Close all browsers immediately.
HttpRequest#
Make HTTP Request
Parameters
| Name | Description |
|---|---|
url |
URL to send request. |
params |
Post Parameters. |
timeout |
Request timeout (miliseconds). |
headers |
Custom HTTP headers. |
Example
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 (') |
