Best practices

  • Use implicit waits for general delays, such as when elements may take a moment to load.
    However, avoid using them for actions that need precise timing or specific conditions.

  • Use explicit waits when you need to wait for something specific – like an element to appear, become clickable, or disappear. You can define exactly how long to wait and what condition must be met.

  • Don’t mix implicit and explicit waits. Combining them can cause unpredictable delays and make your script harder to troubleshoot.

  • Always set a timeout when using explicit waits. This prevents your script from hanging forever if the condition is never met.

1
2
3
4
5
6
7
8
9
10
11
12
13

Common issues

  • Ensure that the element locators used in explicit waits are accurate and unique to avoid targeting the wrong elements or multiple elements unintentionally.

  • Handle exceptions, especially TimeoutException. If the wait times out, catch the error and show a helpful message or try an alternative action.

  • Regularly update the conditions used in explicit waits to align with changes in the web application's UI and functionality to maintain test reliability.

  • Use explicit waits with AJAX-loaded content. These waits help ensure that dynamic elements are fully loaded before you try to interact with them.

1
2
3
4
5
6
7
8
9
10
11
12
13

Try Oxylabs' Proxies & Scraper API

Residential Proxies

Self-Service

Human-like scraping without IP blocking

From

8

Datacenter Proxies

Self-Service

Fast and reliable proxies for cost-efficient scraping

From

1.2

Web scraper API

Self-Service

Public data delivery from a majority of websites

From

49

Useful resources

Puppeteer vs Selenium: Which to Choose
author avatar

Yelyzaveta Hayrapetyan

2025-05-27

Web Scraping with Selenium and Python
Gabija Fatenaite avatar

Gabija Fatenaite

2024-06-13

Scrapy vs. Selenium: Which One is Better?
Scrapy vs. Selenium: Which One is Better?
vytenis kaubre avatar

Vytenis Kaubrė

2023-07-12

Get the latest news from data gathering world

I'm interested