What are the features that are deprecated in Selenium 4?
The significant enhancements in Selenium 4 are also accompanied by a couple of deprecations in this version of Selenium. It is important to note that only breaking changes in Selenium 4 will impact the test code migration from Selenium 3 to Selenium 4.
Here is the brief list of what is deprecated in Selenium 4:
Deprecation of DesiredCapabilities
In Selenium 3, we make extensive use of the DesiredCapabilities when working with a RemoteWebDriver. This is required for setting the browser capabilities so that tests can be run on a cloud-based Selenium Grid like LambdaTest. With Selenium 4, we bid adieu to DesiredCapabilities.
Capabilities objects are now replaced with Options, and we need to create an Options object to use the Driver class. With Selenium 4, we need to set the necessary test requirements (i.e., browser and OS combinations) and pass the object to the Driver constructor.
The FindsBy Method
The methods FindElement and FindElements implemented by the RemoteWebDriver class are used for locating a single WebElement and a list of WebElements, respectively. The FindsBy interfaces are a part of the org.openqa.selenium.internal package is deprecated in Selenium 4.
The changes are internal to the Selenium framework, and Selenium users can continue using the FindElement(By) and FindElements(By) as used in Selenium 3.
New additions to the Actions Class
Actions Class in Selenium provides several methods for performing a single action or a series of actions on the WebElements present in the DOM. Mouse actions (e.g., click, double click, etc.) and Keyboard actions (e.g., keyUp, keyDown, sendKeys) are the two broad categories of Actions.
With Selenium 4, new methods are added to the Actions class, which replaces the classes under the org.openqa.selenium.interactions package.
click(WebElement) is the new method added to the Actions class and it serves as the replacement of moveToElement(onElement).click() method.
Like the method in the versions before Selenium 4, click(WebElement) is used for clicking a web element.
The method moveToElement(element).doubleClick() used for double clicking on a WebElement is replaced with a doubleClick(WebElement) method in Selenium 4.
We demonstrate the usage of DoubleClick along with the ContextClick method.
The method moveToElement(onElement).contextClick() used for right clicking on a WebElement is now replaced with the contextClick(WebElement) method in Selenium 4.
The method moveToElement(Element).clickAndHold() used for clicking on a WebElement without performing the Release action is replaced with clickAndHold(WebElement).
We demonstrate the usage of ClickAndHold along with the Release method.
The release() method, which is used for releasing the pressed mouse button, has been a part of the org.openqa.selenium.interactions.ButtonReleaseAction class. In Selenium 4, the method is a part of the Actions class.
Modifications to the ‘FluentWait’ Class
FluentWait in Selenium is used for performing a Selenium wait for an element when there is no certainty of the time it would take to be visible or clickable. As seen in the FluentWait in Selenium example (with Selenium 3), the withTimeOut() method takes two parameters – int and TimeUnit.
.withTimeout(60, SECONDS) // this defines the total amount of time to wait for
The pollingEvery() method takes two parameters – int and TimeUnit (e.g. SECONDS).
.pollingEvery(2, SECONDS) // this defines the polling frequency
With Selenium 4, the methods withTimeout() and pollingEvery() that are a part of the FluentWait class have been modified. The pollingEvery() method only accepts one parameter – Duration. The Duration can be in Seconds, MilliSeconds, NanoSeconds, Hours, Days, etc. On similar lines, the withTimeOut() method also takes only one parameter – Duration.
Hope it helps!