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
For comprehensive keyboard control documentation, including special keys, key combinations, modifiers, and complete key reference tables, see **[Keyboard Control](keyboard-control.md)**.
225
224
225
+
## Realistic Page Scrolling
226
+
227
+
Pydoll provides a dedicated scroll API that waits for scroll completion before proceeding, making your automations more realistic and reliable.
228
+
229
+
### Basic Directional Scrolling
230
+
231
+
Use the `scroll.by()` method to scroll the page in any direction with precise control:
Navigate quickly to the top or bottom of the page:
264
+
265
+
```python
266
+
import asyncio
267
+
from pydoll.browser.chromium import Chrome
268
+
269
+
asyncdefscroll_to_positions():
270
+
asyncwith Chrome() as browser:
271
+
tab =await browser.start()
272
+
await tab.go_to('https://example.com/article')
273
+
274
+
# Read the beginning of the article
275
+
await asyncio.sleep(2.0)
276
+
277
+
# Smoothly scroll to the bottom
278
+
await tab.scroll.to_bottom(smooth=True)
279
+
280
+
# Pause at the bottom
281
+
await asyncio.sleep(1.5)
282
+
283
+
# Return to the top
284
+
await tab.scroll.to_top(smooth=True)
285
+
286
+
asyncio.run(scroll_to_positions())
287
+
```
288
+
289
+
!!! tip "Smooth vs Instant"
290
+
- **smooth=True**: Uses browser's smooth animation and waits for `scrollend` event
291
+
- **smooth=False**: Instant scrolling for maximum speed when realism isn't critical
292
+
293
+
### Human-Like Scrolling Patterns
294
+
295
+
!!! info "Future Enhancement: Built-in Realistic Scrolling"
296
+
Currently, you must manually implement random scrolling patterns. Future versions will include a `realistic=True` parameter that automatically adds natural variations in scroll distances, speeds, and pauses to mimic human reading behavior.
297
+
298
+
Simulate natural reading and navigation behavior:
299
+
300
+
```python
301
+
import asyncio
302
+
import random
303
+
from pydoll.browser.chromium import Chrome
304
+
from pydoll.constants import ScrollPosition
305
+
306
+
asyncdefhuman_like_scrolling():
307
+
"""Simulate natural scrolling patterns while reading an article."""
Unlike `execute_script("window.scrollBy(...)")` which returns immediately, the `scroll` API uses CDP's `awaitPromise` parameter to wait for the browser's `scrollend` event. This ensures your subsequent actions only execute after scrolling completely finishes.
0 commit comments