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
Understanding the basics
Starting a browser
Thestart() 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.
Navigating to pages
Usebrowser.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:Working with multiple tabs
nodriver makes it easy to manage multiple tabs:Advanced configuration
Customize browser behavior with the Config object:start():
Handling common scenarios
Waiting for page load
Waiting for page load
Working with iframes
Working with iframes
nodriver automatically searches within iframes when using
find() and select() methods:Handling dynamic content
Handling dynamic content
Taking screenshots
Taking screenshots
Common patterns
Form filling
Cookie management
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