Selenium 4 Features
Selenium 4 brings several enhancements and new features to improve the functionality and ease of web automation. Some key features include:
1. W3C WebDriver Standardization
Selenium 4 adheres to the W3C WebDriver standard, improving cross-browser compatibility and stability. This makes the communication between the client (Selenium code) and the browser more consistent.
2. Improved Selenium Grid
3. Relative Locators
Selenium 4 introduces Relative Locators (previously known as Friendly Locators), allowing you to find elements based on their position relative to other elements. For example, above(), below(), toRightOf(), toLeftOf(), and near().
WebElement element = driver.findElement(with(By.tagName("label")).above(By.id("username")));
4. New Window and Tab Management
Selenium 4 introduces APIs for handling multiple windows and tabs more easily. It now provides a simple way to open new windows or tabs and switch between them:
领英推荐
driver.switchTo().newWindow(WindowType.WINDOW);
driver.switchTo().newWindow(WindowType.TAB);
5. Better Documentation
The Selenium documentation has been revamped with improved examples and detailed explanations to make it easier for developers to get started or find specific details.
6. Native Chrome DevTools Protocol (CDP) Integration
Selenium 4 allows you to interact directly with the Chrome DevTools using CDP, enabling features like capturing network logs, controlling performance metrics, emulating geolocation, and more. This provides deeper access to the browser for testing.
DevTools devTools = driver.getDevTools();
devTools.createSession();
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
7. Improved Actions API
Selenium 4 enhances the Actions API, providing more intuitive ways to simulate complex user interactions like drag and drop, key presses, mouse movements, and multi-touch gestures.
8. Deprecated Features
Some older APIs and features have been deprecated, making way for more modern approaches. For example, the DesiredCapabilities class is deprecated, replaced by Options and Capabilities.