Skip to main content
Version: v2

Language Basics

Many cases for gathering data or normalizing data across systems require you click, type and submit forms. All of these are staples of any web automation library and are supported by BrowserQL.

By default, BrowserQL takes care of waiting for these elements to be present in the document, visible to an end user, and scrolls to them in the viewport. You won't have to worry about writing code to handle those small nuanced situations.

This guide will help you to write a first BQL to interact with the browser, going through the following interactions:

Clicking a Button

To click the Free Trial link at the Browserless.io website, you need to navigate to the website with the goto mutation, and then use the click to select the <a> element. In the example below, we'll use the element's href to find the correct element on screen. Also, the visible flag specifies that this element must be visible to the user.

mutation ClickButton {
goto(url: "https://www.browserless.io/" waitUntil: firstContentfulPaint) {
status
}

click(selector: "a[href=\"https://account.browserless.io/signup/email/?plan=starter\"]", visible: true) {
x
y
}
}

Keyboard Typing

Typing is also supported, and works similarly to how the click query does. After navigating to a website, you need to specify the text you want to be typed, along with the selector, telling the query where it should type the content.

mutation TypeInteraction {
goto(url: "https://www.google.com/" waitUntil: firstContentfulPaint) {
status
}

type(
text: "I'm a little teapot!"
selector: "form textarea"
) {
x
y
}
}

HTML Content

You can retrieve HTML content from any website with BrowserQL as well. Use the html mutation after navigating to the website.

mutation HTMLInteraction {
goto(url: "https://www.browserless.io/" waitUntil: firstContentfulPaint) {
status
}

html(
visible: true
) {
time
html
}
}

Retriving Text

To retrieve the text from a element in any website, you can use the text mutation, and add a selector argument to define which element to search for the text content.

mutation TextInteraction {
goto(url: "https://www.example.com/" waitUntil: firstContentfulPaint) {
status
}

text(
selector: "p"
visible: true
) {
time
text
}
}

More interactions

You can also toggle check-boxes, radio-boxes and select elements as well with BrowserQL. Refer to the Editors built-in documentation for more details on those types of queries, or check them out in the BrowserQL Reference.