Skip to main content
Nodriver provides powerful methods for interacting with web page elements. This guide covers the essential techniques for finding and manipulating DOM elements.

Finding elements

Before you can interact with an element, you need to find it. Nodriver offers several methods:

By CSS selector

Use select() for a single element or select_all() for multiple elements:
Both select() and select_all() will retry for up to 10 seconds (configurable via timeout parameter) if the element isn’t immediately found, making them great for waiting for dynamic content.

By text content

Use find() to locate elements containing specific text:
The best_match=True flag finds the element with the most similar text length, helping you get the right “Login” button instead of scripts or metadata containing “login”.
Use find_all() to get all elements containing specific text.

Using XPath

For complex queries, use XPath expressions:

Clicking elements

Nodriver provides two ways to click elements:

Standard click

The click() method simulates a JavaScript click:
From element.py:393-414:

Mouse click

For native browser mouse events, use mouse_click():

Typing text

Send text to input fields using send_keys():
From element.py:708-722:

Selecting options

For dropdown menus and select elements:
From element.py:749-766:

File uploads

Upload files using send_file():
Make sure the file input accepts multiple files if you’re uploading more than one, otherwise the browser might crash.

Mouse interactions

Hovering

Trigger hover effects with mouse_move():

Dragging

Drag elements to different positions:
From mouse_drag_boxes.py example:

Scrolling

Scroll element into view

Get element position

Element properties

Access element attributes directly:

Applying custom JavaScript

Execute custom JavaScript on elements:

Working with shadow DOM

Access shadow root children:

Real-world example

Here’s a complete example from the imgur_upload_image.py demo:

Best practices