Selenium was and it’s one of the most preferred tool to automate cross-browser testing of web apps. It’s been the go-to-tool for web developers and testers to ensure the quality of web applications.
Since Selenium was developed, it received constant updates and fixes, making it one of the most reliable and powerful tool to automate web applications. In 2021, they haven’t forgot about the community and their needs and it got updated to the latest version, Selenium 4, which brings new and cool features worth looking into, that will make web automation even more accessible and efficient.
Let’s dive into some of the new features Selenium 4 brings to table:
W3C WebDriver Specification
One of the most important update under the hood is that Selenium 4 is now fully compliant with the W3C Webdriver specification. What does this even mean?
Well, first of all the browser follows the standard procedure, without requiring encoding and decoding the API requests by the JSON wire protocol. Basically, the WebDriver will interact directly with the browser, making it more reliable in writing stable cross-browser tests and improving its performance.
It will also ensure that Selenium is compatible with other tools and frameworks that uses the same specification, such as Appium.
Improved and optimized Selenium Grid
Hold on, this is really a big and welcomed change. Selenium Grid now comes with Docker support, meaning that it will enable developers / testers to play with containers rather than setting up virtual machines.
More than that, managing is a piece of cake now, because there is no need anymore to set up and start hubs and nodes individually.
QAs can deploy now the grid in 3 modes: Standalone, Hub and Node or Fully distributed.
Another thing worth mentioning is that the Grid now supports IPv6 addresses and communicate with the Grid using HTTPS protocol.
Selenium IDE is back
Do you remember Selenium IDE in the good ol’ days? At some point, they decided to let it go, but now it’s back and alive! More than that, it’s now available for Firefox AND Chrome.
A few things to highlight:
- It has an improved GUI
- It comes with a SIDE tool called Selenium IDE runner that allows QAs to run all sorts of projects on a node.js platform
- A better and improved way to add ‘while’ and ‘if’ conditions
- The locator now has a new ace up in the sleeve – a new locator strategy was developed, so if the web element cannot be found, it will look for relative elements
- The code it generates / you write can now be exported in your preferred language (Java, Python, C# etc)
Awesome and Improved Documentation
The documentation has been improved considerably, and now have an UI that let’s you easily navigate and find what you need. You can check it out here
Selenium 4 brings up what was previously called ‘Friendly locators’, the new Relative Locators, and gives QAs the possibility to locate elements that cannot be easily located otherwise.
This works by locating an adjacent element, with a reliable locator and telling Selenium where to find the element you are interested in. Here are the possibilities:
Above: By email = RelativeLocator.with(By.id(‘input’)).above(By.tagName(‘password’));
Below: By email = RelativeLocator.with(By.id(‘submit’)).below(By.tagName(‘password’));
Left of: By email = RelativeLocator.with(By.id(‘input’)).toLeftOf(By.id(’email’));
Right of: By email = RelativeLocator.with(By.id(‘input’)).toRightOf(By.id(’email’));
Near: By email = RelativeLocator.with(By.id(‘input’)).near(By.id(’email’));
Improved window / tab Manangement
In Selenium 3 and previous versions, to open a new window or tab, you had to create a new driver object and do the switch to new tab or window, along with WindowHandle methods. In Selenium 4, this is all gone, allowing you to create and switch windows / tabs without creating a new WebDriver object.
driver.switchTo().newWindow(WindowType.TAB) or driver.switchTo().newWindow(WindowType.WINDOW)
Awesome improvements in Action Class too
More methods have been added to this class, so we can interact more easily with the web elements. Below you can find a few examples, besides many more:
clickAndHold(WebElement) – replacing moveToElement(onElement).clickAndHold().
doubleClick(WebElement) – replacing moveToElement(onElement).doubleClick().
contextClick(WebElement) – right-click
Network interceptions and listening to JS Exceptions and Console Logs
You can now intercept, validate or modify network requests. You can also add additional headers, fail requests and much more. Also, you can now monitor console errors and JS exception as well.
Selenium 4 brings a lot of new and exciting things to the table, consolidating it’s position as a top and preferred tool to go to for automating web browsers. If you want to see how it compares with Playwright, you can read more about it here.
Until next time, happy testing & coding! 🙂