How to customize RPA scripts
Write custom JavaScript RPA scripts to implement complex automation logic for cloud phones, meeting personalized business needs.
Last updated:
Video demonstration, please visit: Original Yuque Article
Scripting Language
NestBrowser RPA custom scripts are written in JavaScript, with built-in device control APIs that can invoke the following capabilities:
- Simulate touch, swipe, long press, and other gestures
- Simulate text input
- Screenshot and image recognition (coordinate positioning)
- Wait for elements to appear (implicit wait)
- Read and write device clipboard
- Call HTTP interfaces (interact with external systems)
Basic Script Structure
// RPA script example: automatically like the latest post
async function main() {
// Open the target app (package name)
await device.launchApp('com.example.socialapp');
// Wait for the page to load (milliseconds)
await sleep(2000);
// Tap at coordinates (x=200, y=800)
await device.tap(200, 800);
// Input text
await device.inputText('Hello World!');
// Take a screenshot and save it
await device.screenshot('/sdcard/screenshot.png');
console.log('Task completed!');
}
main();
Common API Reference
| Method | Description |
|---|---|
device.tap(x, y) | Tap at screen coordinates |
device.swipe(x1,y1,x2,y2) | Swipe from start point to end point |
device.longPress(x, y) | Long press at coordinates |
device.inputText(text) | Input text into the current focus |
device.keyEvent(key) | Send key events (e.g., BACK, HOME) |
device.screenshot(path) | Save screenshot to specified path |
device.launchApp(pkg) | Launch the app with the specified package name |
device.getClipboard() | Read the content of the device clipboard |
sleep(ms) | Wait for the specified number of milliseconds |
Debugging Scripts
- In the NestBrowser RPA panel, click on “New Script”
- Paste or write the script content
- Click “Debug Run” and view the output in real-time in the log area
- After modifying the script, re-run it without needing to restart the device
Deployment and Scheduled Execution
After the script debugging is successful:
- Click “Save Script” to manage it in the script library
- Set “Scheduled Trigger”: specify daily/hourly automatic execution
- If you need to distribute to multiple devices, use the “Batch RPA” feature