Skip to main content

Search Automation

The click and type mutations let you interact with search bars, dismiss popups, and submit queries. BrowserQL uses level 4 CSS selectors and handles wait conditions automatically.

Basic Usage

The example below navigates to Booking.com, dismisses a sign-in modal, types a destination, and submits the search.

mutation SearchBooking {
goto(url: "https://www.booking.com", waitUntil: networkIdle) {
status
}

closeModal: click(
selector: "button[aria-label='Dismiss sign-in info.']"
visible: true
timeout: 5000
) {
time
}

type(
text: "New York"
selector: "input[name='ss'][placeholder='Where are you going?']"
) {
selector
}

submitSearch: click(
selector: "button[type='submit']"
visible: true
) {
selector
time
}
}

Waiting for Search Results

After submitting a search, use waitForNavigation to pause until the results page loads, then extract the page HTML. See Wait Conditions for more options to wait.

mutation SearchAndExtract {
goto(url: "https://www.booking.com", waitUntil: networkIdle) {
status
}

closeModal: click(
selector: "button[aria-label='Dismiss sign-in info.']"
visible: true
timeout: 5000
) {
time
}

type(
text: "New York"
selector: "input[name='ss'][placeholder='Where are you going?']"
) {
selector
}

submitSearch: click(
selector: "button[type='submit']"
visible: true
) {
selector
time
}

waitForNavigation {
time
}

html {
html
}
}

Handling Conditional Elements

The if mutation runs its nested block only when a selector is present at the time of execution. Use it to interact with elements that appear conditionally, such as date pickers, banners, or upsell prompts.

if does not wait

if evaluates the selector immediately. It does not wait for the element to appear. If the element loads asynchronously, add a waitForSelector call before the if block to ensure the element has time to render.

mutation ConditionalDatePicker {
goto(url: "https://www.booking.com", waitUntil: networkIdle) {
status
}

type(
text: "New York"
selector: "input[name='ss'][placeholder='Where are you going?']"
) {
selector
}

submitSearch: click(
selector: "button[type='submit']"
visible: true
) {
time
}

waitForNavigation {
time
}

ifDateFlexible: if(selector: "#flexible-searchboxdatepicker-tab-trigger", visible: true) {
clickFlexible: click(
selector: "#flexible-searchboxdatepicker-tab-trigger"
) {
time
}
}

html {
html
}
}

Use ifnot to run a block only when a selector is absent.

Next Steps