Best practices

  • Use implicit waits to handle scenarios where elements take time to load, but avoid using them as a default method due to potential increased test execution time.

  • Employ explicit waits to target specific elements or conditions, enhancing test reliability by ensuring elements are interactable before proceeding.

  • Utilize JavaScript execution within explicit waits to check for the 'complete' readyState of the document, ensuring the page has fully loaded before actions are performed.

  • Always define a reasonable timeout for explicit waits to prevent indefinitely hanging tests if the expected 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 updated and accurate to avoid NoSuchElementException.

  • Adjust the timeout settings based on network speed and page complexity to optimize waiting times without causing unnecessary delays.

  • Consider using WebDriverWait in combination with expected_conditions like visibility_of_element_located to handle AJAX-loaded elements more effectively.

  • Regularly review and update your waiting strategies to adapt to changes in web application behavior and structure, ensuring robustness in automated tests.

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