Skip to content

Human Like Interactions

Eduard Dik edited this page Jan 30, 2026 · 1 revision

Human-Like Interactions Overview

Standard Selenium interactions are "perfect": the mouse teleports instantly, typing happens at infinite speed, and clicks always hit the exact center of an element. Modern anti-bot systems (like Akamai, DataDome, or Cloudflare) easily detect these patterns.

osn-selenium replaces these behaviors with mathematical models that simulate human imperfection, micro-movements, and variable timing.


The Core Logic (osn_selenium/instances/_functions.py)

Every "Human-Like" (HM) action is broken down into a series of smaller "parts" or segments, each with its own tiny duration and coordinate offset.

1. Mathematical Mouse Paths (move_to_parts)

Instead of a straight line, the library calculates a path using sinusoidal deviations.

  • Sinusoidal Curve: The path "swings" slightly around the target vector, mimicking the natural arc of a human hand.
  • Micro-Jitter: Each step in the movement includes small random variations in speed and position.
  • Acceleration/Deceleration: The movement starts slower, speeds up in the middle, and slows down as it approaches the target.

2. Realistic Typing (text_input_to_parts)

The hm_send_keys method analyzes the text and applies different delay logic:

  • Consecutive identical keys: 50–70ms delay (simulating a fast double-tap).
  • Different keys: 100–200ms delay (simulating the time taken to move fingers across the keyboard).

3. Smooth Scrolling (scroll_to_parts)

Scrolls are performed in small, randomized steps rather than a single jump, simulating a user flicking a mouse wheel or using a trackpad.


Available Mixins

The human-like functionality is injected into the ActionChains object via specialized mixins.

1. HMMoveMixin

Method Description
hm_move(start, end) Moves the cursor between two Point objects in a natural curve.
hm_move_by_offset(start, x, y) Moves the mouse by a relative amount (dx, dy) starting from the start position.
hm_move_to_element(start, element) Moves the mouse to the center of an element.
hm_move_to_element_with_offset(start, element, x, y) Calculates a path from start to a specific pixel offset relative to the element's top-left corner.
hm_move_to_element_with_random_offset(start, element) Power Feature: Uses JavaScript to find a random visible point within the element's shape (not just the bounding box) and moves there.

2. HMKeyboardMixin

Method Description
hm_send_keys(text) Types text with human-like pauses into the currently focused element.
hm_send_keys_to_element(el, text) Focuses the element first, then performs human-like typing.

3. HMScrollMixin

Method Description
hm_scroll_to_element(el) Smoothly scrolls the element into view, carefully avoiding viewport edges.
hm_scroll_by_amount(x, y) Performs a smooth relative scroll.

Usage Example

The HM methods are fully chainable, just like standard Selenium ActionChains.

# Create an action chain
actions = driver.action_chains()

# Perform a complex, human-like sequence:
# 1. Move to the input field in a natural curve
# 2. Click it
# 3. Type a query with realistic delays
# 4. Scroll down to see results
target_element = driver.find_element(By.NAME, "q")

actions.hm_move_to_element_with_random_offset(start_point, target_element) \
       .click() \
       .hm_send_keys("How to bypass bot detection") \
       .pause(1.5) \
       .hm_scroll_by_amount(0, 500) \
       .perform()

Clone this wiki locally