Skip to main content

Your first script

Let’s create a simple script that opens a browser, navigates to a page, and takes a screenshot.
1

Create a new Python file

Create a file called first_script.py:
2

Run the script

You should see a browser window open, navigate to the page, and then close. A screenshot will be saved in your current directory.
nodriver uses uc.loop().run_until_complete() instead of asyncio.run() for better compatibility and control.

Understanding the basics

Starting a browser

The start() function launches a browser and returns a Browser instance:
By default, nodriver creates a fresh profile that’s automatically cleaned up when the browser closes. This ensures a clean state for each run.
Use browser.get() to navigate:

Finding elements

nodriver provides multiple ways to find elements on a page:
All find methods automatically wait for elements to appear (default timeout: 2.5 seconds). This eliminates the need for explicit waits in most cases.

Interacting with elements

Once you have an element, you can interact with it:

Real-world example

Let’s build a script that searches Google:
This example is adapted from the real examples in the nodriver repository. Check example/network_monitor.py for the full source.

Working with multiple tabs

nodriver makes it easy to manage multiple tabs:

Advanced configuration

Customize browser behavior with the Config object:
Or pass options directly to start():

Handling common scenarios

nodriver automatically searches within iframes when using find() and select() methods:

Common patterns

Form filling

Next steps

Now that you understand the basics, explore more advanced features:

API Reference

Explore the complete API documentation

Examples

Learn from real-world automation scripts

Browser class

Deep dive into browser control and configuration

Tab class

Master page interaction and element manipulation