Mouse Click
curl --request POST \
--url https://api.example.com/browser/sessions/{id}/mouse/click \
--header 'Content-Type: application/json' \
--data '
{
"x": 123,
"y": 123,
"selector": "<string>",
"timeout": 123,
"index": 123,
"button": "<string>",
"holdKeys": [
"<string>"
],
"numClicks": 123
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/mouse/click"
payload = {
"x": 123,
"y": 123,
"selector": "<string>",
"timeout": 123,
"index": 123,
"button": "<string>",
"holdKeys": ["<string>"],
"numClicks": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
x: 123,
y: 123,
selector: '<string>',
timeout: 123,
index: 123,
button: '<string>',
holdKeys: ['<string>'],
numClicks: 123
})
};
fetch('https://api.example.com/browser/sessions/{id}/mouse/click', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/browser/sessions/{id}/mouse/click",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'x' => 123,
'y' => 123,
'selector' => '<string>',
'timeout' => 123,
'index' => 123,
'button' => '<string>',
'holdKeys' => [
'<string>'
],
'numClicks' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/browser/sessions/{id}/mouse/click"
payload := strings.NewReader("{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/browser/sessions/{id}/mouse/click")
.header("Content-Type", "application/json")
.body("{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/mouse/click")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}"
response = http.request(request)
puts response.read_body{
"x": 123,
"y": 123
}Browser Sessions
Mouse Click
Simulate a mouse click on the session’s active page, by coordinates or by CSS selector.
POST
/
browser
/
sessions
/
{id}
/
mouse
/
click
Mouse Click
curl --request POST \
--url https://api.example.com/browser/sessions/{id}/mouse/click \
--header 'Content-Type: application/json' \
--data '
{
"x": 123,
"y": 123,
"selector": "<string>",
"timeout": 123,
"index": 123,
"button": "<string>",
"holdKeys": [
"<string>"
],
"numClicks": 123
}
'import requests
url = "https://api.example.com/browser/sessions/{id}/mouse/click"
payload = {
"x": 123,
"y": 123,
"selector": "<string>",
"timeout": 123,
"index": 123,
"button": "<string>",
"holdKeys": ["<string>"],
"numClicks": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
x: 123,
y: 123,
selector: '<string>',
timeout: 123,
index: 123,
button: '<string>',
holdKeys: ['<string>'],
numClicks: 123
})
};
fetch('https://api.example.com/browser/sessions/{id}/mouse/click', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/browser/sessions/{id}/mouse/click",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'x' => 123,
'y' => 123,
'selector' => '<string>',
'timeout' => 123,
'index' => 123,
'button' => '<string>',
'holdKeys' => [
'<string>'
],
'numClicks' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/browser/sessions/{id}/mouse/click"
payload := strings.NewReader("{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/browser/sessions/{id}/mouse/click")
.header("Content-Type", "application/json")
.body("{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/browser/sessions/{id}/mouse/click")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"x\": 123,\n \"y\": 123,\n \"selector\": \"<string>\",\n \"timeout\": 123,\n \"index\": 123,\n \"button\": \"<string>\",\n \"holdKeys\": [\n \"<string>\"\n ],\n \"numClicks\": 123\n}"
response = http.request(request)
puts response.read_body{
"x": 123,
"y": 123
}Overview
The/browser/sessions/{id}/mouse/click endpoint dispatches a mouse click against the currently active page inside a browser session. It supports two modes:
- Coordinates — click at
(x, y)in viewport CSS pixels. - Selector — click the center of an element matched by a CSS selector. Waits for the element to be visible.
(x, y) or selector, never both.
Path Parameters
string
required
Browser session ID (UUID). Create via
POST /browser/sessions.Body
integer
X coordinate in viewport CSS pixels. Required together with
y when selector is omitted.integer
Y coordinate in viewport CSS pixels. Required together with
x when selector is omitted.string
CSS selector of the element to click. Mutually exclusive with
x/y. Clicks the center of the element’s bounding box.integer
default:"5000"
How long to wait (ms) for the selector to become visible. Ignored when using coordinates.
integer
default:"0"
Which match to click when the selector resolves to multiple elements (0-based).
string
default:"left"
Mouse button to press. One of
left, right, middle, back, forward. The back and forward buttons map to the side buttons used for browser navigation on some sites.string[]
Modifier keys held for the duration of the click. Each value must be one of
Shift, Control, Alt, Meta.integer
default:"1"
Number of clicks to issue at the same point. Capped at 10.
Example Request
curl -X POST "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/mouse/click" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"x": 120,
"y": 240,
"button": "left"
}'
curl -X POST "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/mouse/click" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"selector": "button[type=submit]",
"holdKeys": ["Shift"]
}'
const response = await fetch(
"https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/mouse/click",
{
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
selector: "button[type=submit]",
numClicks: 2,
}),
},
);
const data = await response.json();
import requests
url = "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/mouse/click"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
}
payload = {
"selector": "button[type=submit]",
"numClicks": 2,
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
Response
Success Response (200)
integer
X coordinate actually clicked (in viewport CSS pixels). For selector mode, this is the center of the resolved element.
integer
Y coordinate actually clicked (in viewport CSS pixels).
{
"x": 120,
"y": 240
}
Error Responses
| Status | Description |
|---|---|
400 | Invalid body — both coordinate and selector modes supplied, selector didn’t match, unknown button/modifier, or numClicks out of range. |
401 | Unauthorized — invalid or missing API key. |
404 | Session not found or not owned by the caller. |
503 | The browser session is temporarily unreachable. |
Notes
- Coordinate system: coordinates are viewport-relative in CSS pixels. On HiDPI pages, they do not need to be scaled by
devicePixelRatio— the browser handles that internally. - Selector mode: the endpoint waits up to
timeoutms for the first match to become visible, then clicks the center of its bounding box. Useindexto target the Nth match. - Modifiers:
holdKeysare held for the full duration of every click in a multi-click sequence.
Was this page helpful?