Skip to main content

BQL Language Basics

Learning a new language can be intimidating, but mastering BQL doesn't have to be difficult. This guide provides a straightforward overview of how to write BQL with clear examples.

BQL Script Structure

A BQL script is one mutation block containing one or more actions. Actions run in order, top to bottom. Each action has a name, optional arguments that configure it, and response fields that define what data it returns.

mutation ScriptName {
goto(url: "https://example.com", waitUntil: domContentLoaded) {
status
}
text(selector: "h1") {
text
}
screenshot(type: png) {
base64
}
}
  • goto, text, and screenshot are the action names.
  • url, waitUntil, selector, and type are arguments. They configure how the action runs.
  • status, text, and base64 are response fields. They define what data gets returned.

Find all available actions, arguments, and response fields in the BQL API Reference or the Built-in Documentation in the IDE.

Aliases

Because a BQL script is a single mutation block, every action name must be unique. If you use the same action twice, BQL cannot distinguish them in the response.

This fails:

mutation LoginForm {
goto(url: "https://practicetestautomation.com/practice-test-login/") {
status
}
type(selector: "#username", text: "student") {
time
}
type(selector: "#password", text: "Password123") { # ❌ duplicate action name
time
}
click(selector: "#submit") {
time
}
}

Fix it by prefixing each duplicate action with an alias:

mutation LoginForm {
goto(url: "https://practicetestautomation.com/practice-test-login/") {
status
}
typeUsername: type(selector: "#username", text: "student") {
time
}
typePassword: type(selector: "#password", text: "Password123") {
time
}
click(selector: "#submit") {
time
}
}

Aliases also become the keys in the JSON response, making the result easier to parse.

For GraphQL readers

In GraphQL terms, each action is a mutation field on the root mutation type. Aliases are required because GraphQL does not allow duplicate field names within the same selection set.

Core Actions

ActionWhat it doesReturns
gotoNavigate to a URLstatus, time
clickClick an elementx, y, time
typeType text into an elementtime, selector
selectSelect an option from a dropdownvalue, selector
textExtract visible text from an elementtext
htmlExtract raw HTML from an elementhtml
screenshotCapture a screenshotbase64
solveSolve a CAPTCHAfound, solved, time

For the full list of available actions and their arguments, see the BQL API Reference.

Next Steps

BrowserQL simplifies web automation with intuitive commands and a structure that's easy to learn. Explore these key areas to build more sophisticated automations: