Selenium 4 introduced several major updates that make it a significant improvement over previous versions:
- W3C Standardization: WebDriver is now a W3C standard, which ensures more stable and consistent cross-browser testing. This means there’s a standardized communication protocol between the browser and the driver, leading to more reliable test automation.
- Revamped Selenium Grid: Selenium Grid 4 has been completely rewritten. The setup is much simpler, with the Hub and Node components combined into a single JAR file. It supports modern technologies like Docker and Kubernetes for more scalable and flexible test infrastructure. It also now supports IPv6 and HTTPS.
- Relative Locators: Also known as “Friendly Locators,” this new feature allows you to locate elements based on their visual proximity to other elements using methods like
above(),below(),toLeftOf(),toRightOf(), andnear(). This makes your locators more intuitive and robust. - Chrome DevTools Protocol (CDP) Integration: Selenium 4 provides native support for the Chrome DevTools Protocol, allowing advanced browser interactions like mocking geolocation, capturing network traffic, and simulating network conditions.
- Simplified Window/Tab Handling: Selenium 4 introduced a new API to easily open new windows or tabs within the same session using
driver.switchTo().newWindow(WindowType.TAB)ordriver.switchTo().newWindow(WindowType.WINDOW)