Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

API Reference

waxnet edited this page Sep 22, 2024 · 32 revisions

This section is designed to provide you with comprehensive information and examples to help you understand the Synth API.
If you have any questions or need further assistance, don’t forget to check out our Community & Support page.


Main

Data

Screen

Http

File System

Other

Classes

Data Types


StartDriver

driver = StartDriver(browser, width, height, userAgent)

Arguments

  • browser (string)
    Specifies the name of the browser to launch (e.g. "chrome", "firefox").
  • width (number)
    Sets the width of the browser window in pixels.
  • height (number)
    Sets the height of the browser window in pixels.
  • userAgent (string - optional)
    Defines the user agent string for the browser. This string is sent with requests to simulate different browsers or devices.

Return value

  • driver (Driver)
    Driver class.

Example

local driver = StartDriver("chrome", 450, 600)

driver:Browse("https://github.com/waxnet/Synth")
Wait(3)
driver:Quit()

GetRandomString

data = GetRandomString(length)

Arguments

  • length (number)
    Specifies the length of the random string.

Return value

  • data (string)
    Random string.

Example

Print(GetRandomString(20))

GetRandomNumber

data = GetRandomNumber(minimum, maximum)

Arguments

  • minimum (number)
    Specifies the lower bound of the range.
  • maximum (number)
    Specifies the upper bound of the range.

Return value

  • data (number)
    Random number.

Example

Wait(GetRandomNumber(1, 10))
Print("Hello World!")

Print

Print(text, color)

Arguments

  • text (string)
    Text to be printed on screen.
  • color (string)
    Text color. (default white)

Example

Print("Hello World!", "Red")

Input

data = Input(text, color)

Arguments

  • text (string)
    Text to be printed on screen.
  • color (string)
    Text color. (default white)

Return value

  • data (string)
    Input text from user.

Example

local answer = Input("Do you want to print 'Hello World!' ? : ")

if answer == "y" then
    Print("Hello World!")
end

Clear

Clear()

Info

  • Clears screen.

Example

Print("Hello World! 1")
Clear()
Print("Hello World! 2")

SendGetRequest

data = SendGetRequest(url)

Arguments

  • url (string) Url to make the request to.

Return value

  • data (string)
    Returns the response content or error data if the request failed.

Example

local data = SendGetRequest("https://www.mywebsite.com/text.txt")

Print(data)

SendPostRequest

data = SendPostRequest(url, jsonData)

Arguments

  • url (string) Url to make the request to.
  • jsonData (table) Json data to send with the request.

Return value

  • data (string)
    Returns the response content or error data if the request failed.

Example

local data = SendPostRequest(
    "https://www.mywebsite.com",
    {
        name = "John",
        age = 30
    }
)

Print(data)

DownloadFile

data = DownloadFile(url, filePath)

Arguments

  • url (string) Url of the file to download.
  • filePath (string) Path of the file to write to.

Return value

  • data (bool)
    True if the file was downloaded successfully, false otherwise.

Example

local success = DownloadFile("https://www.mywebsite.com/image.png", "myimage.png")

if success then
    Print("File downloaded successfully.")
end

WriteToFile

WriteToFile(filePath, data)

Arguments

  • filePath (string)
    Path of the file to write to.
  • data (string)
    Text to write to file.

Example

WriteToFile("data.txt", "1234567890")

AppendToFile

AppendToFile(filePath, data)

Arguments

  • filePath (string)
    Path of the file to write to.
  • data (string)
    Text to append to file.

Example

AppendToFile("data.txt", "\n1234567890")

ReadFromFile

data = ReadFromFile(filePath)

Arguments

  • filePath (string)
    Path of the file to write to.

Return value

  • data (string)
    Text from file. (empty string if file is not found)

Example

local data = ReadFromFile("data.txt")

Print(data)

DeleteFile

DeleteFile(filePath)

Arguments

  • filePath (string)
    Path of the file to delete.

Example

if DoesFileExist("data.txt") then
    DeleteFile("data.txt")
end

CreateFolder

CreateFolder(folderPath)

Arguments

  • folderPath (string)
    Path of the folder to create.

Example

CreateFolder("MyScript")

DeleteFolder

DeleteFolder(folderPath)

Arguments

  • folderPath (string)
    Path of the folder to delete.

Example

if DoesFolderExist("MyScript") then
    DeleteFolder("MyScript")
end

DoesFileExist

data = DoesFileExist(filePath)

Arguments

  • filePath (string)
    Path of the file to check.

Return value

  • data (bool)
    True if file exists, false otherwise.

Example

if DoesFileExist("data.txt") then
    DeleteFile("data.txt")
end

DoesFolderExist

data = DoesFolderExist(folderPath)

Arguments

  • folderPath (string)
    Path of the folder to check.

Return value

  • data (bool)
    True if folder exists, false otherwise.

Example

if DoesFolderExist("MyScript") then
    DeleteFolder("MyScript")
end

SetScriptTitle

SetScriptTitle(title)

Arguments

  • title (string)
    Specifies the script title.

Example

SetScriptTitle("My Script")

Wait

data = Wait(seconds)

Arguments

  • seconds (number)
    Specifies the amount of seconds to wait. (default is 0)

Return value

  • data (bool)
    Returns true after waiting.

Example

local counter = 0

repeat
    Print("Hello World!")
    Wait(1)
    counter = counter + 1
until counter == 10

Driver

Properties

Property Type Description
Title string Gets the title of the browser window.
Url string Gets the URL the browser is currently displaying.
PageSource string Gets the source of the page last loaded by the browser.
Window Window Gets the driver window.
Network Network Gets the driver network manager.
Cookies Cookies Gets the driver cookie manager.

Methods

Method Type Description
Quit() void Quits the driver.
Browse(url : string) void Load a new web page in the browser window.
Forward() void Move a single "item" forward in the browser's history.
Back() void Move a single "item" backward in the browser's history.
Refresh() void Refreshes the current page.
FindElement(identifier : string, method : string - optional) Element Finds the first element using the given method.
FindElements(identifier : string, method : string - optional) Element Array Finds elements using the given method.
WaitForElement(timeout : number, identifier : string, method : string - optional) Element Waits for the first element using the given method.

Example

local driver = StartDriver("chrome", 450, 600)

driver:Browse("https://www.supercoolwebsite.com/")

-- (Id, Name, ClassName, TagName, LinkText, PartialLinkText, CssSelector, XPath)
local textBox = driver:WaitForElement(30, "TextBox", "Id")
local submitButton = driver:WaitForElement(30, "SubmitButton") -- default method is Id

textBox.Text = "Hello World!"
submitButton:Click()

local buttons = driver:FindElements("Buttons")
for index = 0, buttons.Length - 1 do
    local button = buttons[index]

    button:Click()
end

driver:Quit()

Element

Properties

Property Type Description
Text string Gets or sets the visible text of the element.
TagName string Gets the tag name of the element.
Enabled bool True if the element is enabled, false otherwise.
Selected bool True if the element is selected, false otherwise.
Displayed bool True if the element is displayed, false otherwise.
Position Vector2 Gets the position of the element.
Size Vector2 Gets the size of the element.

Methods

Method Type Description
Click() void Clicks the element.
Submit() void Submits the element to the web server.
GetAttribute(attributeName : string) string Gets the value of the specified attribute for the element.
GetCssValue(propertyName : string) string Gets the value of the specified CSS property for the element.
GetDomProperty(propertyName : string) string Gets the value of the specified JavaScript property for the element.
FindElement(identifier : string, method : string - optional) Element Finds the first sub-element using the given method.
FindElements(identifier : string, method : string - optional) Element Array Finds sub-elements using the given method.

Example

local driver = StartDriver("chrome", 450, 600)

driver:Browse("https://www.supercoolwebsite.com/")

-- (Id, Name, ClassName, TagName, LinkText, PartialLinkText, CssSelector, XPath)
local textBox = driver:WaitForElement(30, "TextBox", "Id")
local submitButton = driver:WaitForElement(30, "SubmitButton") -- default method is Id

textBox.Text = "Hello World!"
submitButton:Click()

local buttons = driver:FindElements("Buttons")
for index = 0, buttons.Length - 1 do
    local button = buttons[index]

    button:Click()
end

driver:Quit()

Window

Properties

Property Type Description
Position Vector2 Gets or sets the position of the driver window.
Size Vector2 Gets the sets the size of the driver window.

Methods

Method Type Description
Fullscreen() void Fullscreens the driver window.
Maximize() void Maximizes the driver window.
Minimize() void Minimizes the driver window.

Example

local driver = StartDriver("chrome", 450, 600)
local window = driver.Window

window.Position = Vector2.New(400, 400)
window.Size = Vector2.New(400, 400)

Network

Methods

Method Type Description
Connect(function : function, traffic : string) Connection Connects a function to the specified network traffic and returns a connection handle.
Disconnect(connection : Connection) void Disconnects a connection.
StartMonitoring() void Starts monitoring the network traffic.
StopMonitoring() void Stops monitoring the network traffic.

Example

local driver = StartDriver("chrome", 450, 600)

Wait(3)
local network = driver.Network
local connection = network:Connect(function(data)
	Print(data.Url)
end, "requests")

network:StartMonitoring()
driver:Browse("https://google.com/")
network:StopMonitoring()

network:Disconnect(connection)

Wait(3)
driver:Quit()

(not supported on Firefox)


Cookies

Properties

Property Type Description
AllCookies Cookie Array Gets all Cookies defined for the current page.

Methods

Method Type Description
GetCookie(cookieName : string) Cookie Gets a Cookie with the specified name.
AddCookie(cookie : Cookie) void Adds a Cookie to the current page.
DeleteCookie(cookie : Cookie) void Deletes the specified Cookie from the page.
DeleteCookie(cookieName : string) void Deletes the Cookie with the specified name from the page.
DeleteAllCookies() void Deletes all Cookies from the page.

Example

local cookie = Cookie.New("TestCookie", "TestValue")

Print(cookie.Name)
Print(cookie.Value)

Vector2

Constructor

Method Type Description
New(x : int, y : int) Vector2 Creates a new Vector2 instance.

Properties

Property Type Description
X int Gets or sets the X value.
Y int Gets or sets the Y value.

Example

local vector2 = Vector2.New(100, 100)

Print("X : "..tostring(vector2.X).." - Y : "..tostring(vector2.Y))
vector2.X = 200
vector2.Y = 200
Print("X : "..tostring(vector2.X).." - Y : "..tostring(vector2.Y))

Request

Properties

Property Type Description
Id string Gets the request id.
Url string Gets the request url.
Method string Gets the HTTP request method.
PostData string Gets the request post data.
Headers Dictionary<string, string> Gets the request headers.

Example

local driver = StartDriver("chrome", 450, 600)

Wait(3)
local network = driver.Network
local connection = network:Connect(function(data)
	Print(data.Url)
end, "requests")

network:StartMonitoring()
driver:Browse("https://google.com/")
network:StopMonitoring()

network:Disconnect(connection)

Wait(3)
driver:Quit()

Response

Properties

Property Type Description
Id string Gets the request id.
Url string Gets the response url.
StatusCode number Gets the response status code.
Body string Gets the response body.
Content string Gets the response content.
ResourceType string Gets the response resource type.
Headers Dictionary<string, string> Gets the response headers.

Example

local driver = StartDriver("chrome", 450, 600)

Wait(3)
local network = driver.Network
local connection = network:Connect(function(data)
	Print(data.Url)
end, "responses")

network:StartMonitoring()
driver:Browse("https://google.com/")
network:StopMonitoring()

network:Disconnect(connection)

Wait(3)
driver:Quit()

Cookie

Constructor

Method Type Description
New(name : string, value : string, path : string - optional, domain : string - optional) Cookie Creates a new Cookie instance.
NewSecure(name : string, value : string, path : string, domain : string, secure : bool, isHttpOnly : bool, sameSite : string) Cookie Creates a new secure Cookie instance.

Properties

Property Type Description
Name string Gets the Cookie name.
Value string Gets the Cookie value.
Path string Gets the Cookie path.
Domain string Gets the Cookie domain.
Expiry string Gets the Cookie expiry date. (dd/MM/yy-HH:mm:ss)
Secure bool True if cookie is secure, false otherwise.
IsHttpOnly bool True if cookie is http only, false otherwise.
SameSite string Gets the same site setting for the Cookie.

Example

local cookie = Cookie.New("TestCookie", "TestValue")

Print(cookie.Name)
Print(cookie.Value)