This endpoint allows you to simulate user input in Chrome by typing text into an element specified by a CSS selector. This is useful for filling out forms, entering search queries, or any other text input operations in a Chrome browser.
{
"selector": "string", // CSS selector to identify the target input element
"text": "string" // The text to type into the specified input element
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| selector | string | Yes | CSS selector to identify the target input element (e.g., "#search-input", "input[name='username']"). |
| text | string | Yes | The text to type into the specified input element. |
{
"success": boolean, // Whether the operation was successful
"message": "string", // Result message
"timestamp": "string" // ISO 8601 date format
}
| Field | Type | Description |
|---|---|---|
| success | boolean | Indicates whether the input operation was successful. |
| message | string | A message describing the outcome of the operation, including details about any errors that occurred. |
| timestamp | string | The time when the response was generated, in ISO 8601 date format. |
import requests
import json
def simulate_input_in_chrome(selector: str, text: str, api_key: str) -> dict:
"""
Simulates user input in Chrome by typing text into an element specified by a CSS selector.
Args:
selector: CSS selector to identify the target input element
text: The text to type into the specified input element
api_key: Your API key for authentication
Returns:
dict: The response from the server
"""
url = "http://localhost:5000/tools-api/chrome/simulate-input"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"selector": selector,
"text": text
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Example usage
if __name__ == "__main__":
API_KEY = "your_api_key_here"
# Example: Type a search query in a search box
result = simulate_input_in_chrome(
selector="#search-input",
text="Smooth Operator documentation",
api_key=API_KEY
)
print(f"Success: {result['success']}")
print(f"Message: {result['message']}")
interface SimulateInputRequest {
selector: string;
text: string;
}
interface ActionResponse {
success: boolean;
message: string;
timestamp: string;
}
/**
* Simulates user input in Chrome by typing text into an element specified by a CSS selector.
*
* @param selector - CSS selector to identify the target input element
* @param text - The text to type into the specified input element
* @param apiKey - Your API key for authentication
* @returns A promise that resolves to the action response
*/
async function simulateInputInChrome(
selector: string,
text: string,
apiKey: string
): Promise {
const url = 'http://localhost:5000/tools-api/chrome/simulate-input';
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
};
const requestBody: SimulateInputRequest = {
selector,
text
};
const response = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(requestBody)
});
return await response.json();
}
// Example usage
(async () => {
const API_KEY = 'your_api_key_here';
try {
// Example: Type a search query in a search box
const result = await simulateInputInChrome(
'#search-input',
'Smooth Operator documentation',
API_KEY
);
console.log(`Success: ${result.success}`);
console.log(`Message: ${result.message}`);
} catch (error) {
console.error('Error simulating input:', error);
}
})();
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class SimulateInputRequest
{
public string Selector { get; set; }
public string Text { get; set; }
}
public class ActionResponse
{
public bool Success { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
public class ToolsServerClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
public ToolsServerClient(string apiKey)
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:5000/");
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
_apiKey = apiKey;
}
///
/// Simulates user input in Chrome by typing text into an element specified by a CSS selector.
///
/// CSS selector to identify the target input element
/// The text to type into the specified input element
/// Response indicating success or failure of the operation
public async Task SimulateInputInChromeAsync(string selector, string text)
{
var request = new SimulateInputRequest
{
Selector = selector,
Text = text
};
var jsonContent = JsonSerializer.Serialize(request);
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("tools-api/chrome/simulate-input", content);
var responseBody = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize(responseBody, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
}
}
// Example usage
class Program
{
static async Task Main(string[] args)
{
string apiKey = "your_api_key_here";
var client = new ToolsServerClient(apiKey);
try
{
// Example: Type a search query in a search box
var result = await client.SimulateInputInChromeAsync(
"#search-input",
"Smooth Operator documentation"
);
Console.WriteLine($"Success: {result.Success}");
Console.WriteLine($"Message: {result.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
This example demonstrates how to fill out a username and password field in a login form.
// Request
POST /tools-api/chrome/simulate-input
{
"selector": "input[name='username']",
"text": "myusername"
}
// Response
{
"success": true,
"message": "Successfully input text into element with selector 'input[name='username']'",
"timestamp": "2023-03-12T10:15:30.123Z"
}
// Then, input password
POST /tools-api/chrome/simulate-input
{
"selector": "input[name='password']",
"text": "mypassword"
}
This example shows how to enter a search query into a search input field.
// Request
POST /tools-api/chrome/simulate-input
{
"selector": "#search-box",
"text": "automated browser control with smooth operator"
}
// Response
{
"success": true,
"message": "Successfully input text into element with selector '#search-box'",
"timestamp": "2023-03-12T10:20:15.123Z"
}