You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Python module for automating interactions to mimic human behavior in standalone apps or browsers when using Selenium, Pyppeteer, or Playwright. Provides utilities to programmatically move the mouse cursor, click on page elements, type text, and scroll as if performed by a human user.
4
-
3
+
Emunium is a Python module that helps you automate interactions in a human-like way. It works with standalone applications or browsers when using Selenium, Pyppeteer, or Playwright. Emunium makes the mouse movements, clicks, typing, and scrolling appear more natural, which can help your tests avoid detection.
# Find the search icon using an image and click it
20
26
elements = emunium.find_elements('search_icon.png', min_confidence=0.8)
21
27
emunium.click_at(elements[0])
22
28
```
23
29
30
+
---
31
+
32
+
## 🔍 OCR Text Search (only in Standalone)
33
+
34
+
Emunium can also search for text on the screen using Optical Character Recognition (OCR). To use this feature, create your Emunium instance with OCR enabled. This uses [EasyOCR](https://github.com/JaidedAI/EasyOCR) under the hood.
35
+
36
+
### How It Works
37
+
38
+
The new `find_text_elements()` method scans the screen for text that matches your query. You can adjust the minimum confidence and limit the number of results.
39
+
40
+
### Example
41
+
42
+
```python
43
+
from emunium import Emunium
44
+
45
+
# Create an Emunium instance with OCR enabled.
46
+
emunium = Emunium(ocr=True, use_gpu=True, langs=['en']) # use_gpu is default True, langs is default ['en'], ocr is default False
47
+
48
+
# Search for text that contains the word "Submit"
49
+
text_elements = emunium.find_text_elements('Submit', min_confidence=0.8) # min_confidence is default 0.8
50
+
51
+
# If the text is found, click on the first occurrence.
52
+
if text_elements:
53
+
emunium.click_at(text_elements[0])
54
+
```
55
+
56
+
*Note:* Make sure you have EasyOCR installed by running `pip install easyocr` before using the OCR feature.
57
+
58
+
---
59
+
60
+
Quickstarts for one of more cases. The code below opens DuckDuckGo, types a query, and clicks the search button.
In standalone mode, Emunium can locate elements on the screen using image matching with the `find_elements` method:
167
+
## 🔎 Finding Elements on the Screen (only in Standalone)
125
168
126
-
```python
127
-
elements = emunium.find_elements('search_icon.png', min_confidence=0.8)
128
-
```
169
+
Emunium uses image matching to find elements:
129
170
130
-
The `find_elements` method takes the following parameters:
171
+
-**find_elements():**
172
+
Locate elements on the screen using an image file.
131
173
132
-
-`image_path` (required): The path to the image file to search for on the screen.
133
-
-`min_confidence` (optional, default 0.8): The minimum confidence level (between 0 and 1) for image matching. Higher values result in more precise matching but may miss some elements.
134
-
-`target_height` (optional): The expected height of the elements to find. If provided along with `target_width`, elements that don't match the specified size (within a tolerance based on `min_confidence`) will be filtered out.
135
-
-`target_width` (optional): The expected width of the elements to find. Must be provided together with `target_height`.
136
-
-`max_elements` (optional, default 0): The maximum number of elements to return. If set to 0 or not provided, all matching elements will be returned.
174
+
```python
175
+
elements = emunium.find_elements('search_icon.png', min_confidence=0.8)
176
+
```
137
177
138
-
The `find_elements` method returns a list of dictionaries, each containing the 'x' and 'y' coordinates of the center point of a matched element.
178
+
You can also set target sizes and limit the number of elements found.
139
179
180
+
---
140
181
141
182
## ⌨️ Typing Text
142
183
143
-
The `type_at()` method moves to the provided element via `move_to()`, clicks it via `click_to()`, and types the provided text in a "silent" way, spreading out key presses over time with small randomizations to mimic human typing.
184
+
The `type_at()` method moves to an element, clicks on it, and types text in a "silent" way. This method mimics human typing by spreading out key presses with small, random delays.
144
185
145
-
Options:
146
-
-`characters_per_minute` - typing speed in characters per minute (default 280)
147
-
-`offset` - randomization (threshold) in milliseconds between key presses (default 20ms)
186
+
Options include:
187
+
-`characters_per_minute`: Typing speed (default is 280 CPM).
188
+
-`offset`: Random delay (default is 20ms).
189
+
190
+
---
148
191
149
192
## 📜 Scrolling Pages
150
193
151
-
The `scroll_to()` method scrolls the page to bring the provided element into view using smooth scrolling.
194
+
The `scroll_to()` method scrolls smoothly to bring an element into view. It uses timeouts and checks to ensure smooth scrolling even when there are minor hiccups.
152
195
153
-
Includes timeouts and checks to handle issues with scrolling getting stuck.
196
+
---
154
197
155
198
## 🏁 Conclusion
156
199
157
-
Emunium provides a set of utilities to help automate browser interactions in a more human-like way when using Selenium, Pyppeteer, or Playwright. By moving the mouse, clicking, typing, and scrolling in a less robotic fashion, tests can avoid detection and run more reliably.
158
-
159
-
While basic automation scripts can still get the job done, Emunium aims to make tests appear even more life-like. Using the randomizations and smooth behaviors it offers can be beneficial for automation projects that require avoiding detections.
200
+
Emunium provides a set of easy-to-use tools for automating user interactions. Whether you need to automate clicks, type text, or even search for text on your screen using OCR, Emunium offers flexible solutions for both browser and standalone applications. Its human-like behavior helps make your tests more robust and less likely to be detected as automation.
0 commit comments