Select Page

Category Selected: Selenium Testing

47 results Found

People also read

API Testing

Postman API Automation Testing Tutorial

Automation Testing

Top 10 AI Automation Testing Tools

Automation Testing

Talk to our Experts

Amazing clients who
trust us

Selenium Grid 4 – Distributed Execution

Selenium Grid 4 – Distributed Execution

As we all are aware of the fact that, Selenium 4 has not been released yet. However, three alpha versions have been released. Selenium Grid has only two components Hub and Node. On the other hand in Selenium Grid 4, we have four components namely – Router, Sessions Map, Distributor, and Node. Selenium 4 has introduced new architecture for Grid. Let’s understand how Selenium Grid 4 works with the three new processes.

Step #1-Start Sessions Map

Download selenium-server-4.0.0-alpha-2.jar & Chrome Driver in a folder and run the below command to start Sessions Map process.

 java -jar selenium-server-4.0.0-alpha-2.jar sessions

What is Sessions Map? Session Map is one of the Selenium Grid Processes. Whenever a node/session is created, Node URI/Session ID gets stored in Sessions Map. Why it is getting stored here is another question. You will understand this at the last step.

selenium grid 4

Step #2-Start Distributor

Run the below command to start the distributor process.

 java -jar selenium-server-4.0.0-alpha-2.jar distributor --sessions http://localhost:5556

All Selenium Grid nodes get attached under the Distributor process. If Selenium client code sends a create session request, then Distributor is responsible for assigning a node.

Selenium Grid 4 Distributor

Step #3-Router Process

All the client requests will be received by Router. If the request is for creating a new session, then it will be redirected to the Distributor process. All other requests will be sent to the node associated with the request after querying the node URI from Sessions Map using the Session ID. Use the below command to start the router process.

 java -jar selenium-server.jar router --sessions http://localhost:5556 --distributor http://localhost:5553

Selenium Grid 4 Router

Step #4-Create a node

While creating a node, you do need to pass all the driver details. Drivers will get auto-detected if the exe/binary files are available in the folder where you have saved the Selenium Server jar file. Once the node is created under the distributor, the node details along with Node URI are updated in Session Map. For a thorough understanding, Please refer to the below diagram.

 java -jar selenium-server-4.0.0-alpha-2.jar node --detect-drivers

Selenium Grid 4 Node

Step #5-Start a remote session

Invoke the remote webdriver which will send the creation request to router. Please note – Use http://localhost:4444. Not http://localhost:4444/wd/hub.

 DesiredCapabilities capability = new DesiredCapabilities();

 RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"),capability);

Grid 4 Session Creation

Once the session is created under the node, the session ID gets updated in the Session map for the node. So that Router can easily identify the node to send the other client requests directly.

Step #6-Router sends command to node

Apart from the session creation call, all other requests will be forwarded to Node from Router directly. Each client request has a Session ID. Using the session ID, the Router queries the Node URI
and finds the node which holds the session.

Selenium Grid Commands

In the older version of Selenium Grid, these processes occur inside the Hub process. Hence we are not aware of the process which happens at the backdrop. Though the setup is complex. Modernization will help us to troubleshoot failures and we can set up our own distributed execution elegantly.

The Test Automation Best Practices to Follow for Success

The Test Automation Best Practices to Follow for Success

Even though automation is a great asset that can greatly reduce the efforts needed in software testing, it has to be used properly to reap all its benefits. There are various instances where software testing companies have tried to implement automation in their various projects and failed due to various complications. On the other hand, we’ve followed the test automation best practices in all our automation projects and have witnessed tremendous success. By doing so, we have been able to focus on aspects such as exploratory testing to unearth hidden bugs instead of focusing on repetitive tasks. So these test automation best practices can help you reduce the time needed to reach the market, increase outcome precision, avoid human error and eventually assure maximum product quality.

Decide which tests to Automate:

Similarly, it is also not recommended to automate every single test that can be automated. Apart from that, certain types of testing like exploratory testing and accessibility testing need manual efforts for it to be successful. Trying to use automation there will not result in the loss of time and effort, it will also reduce the overall quality of the product that you are testing.

So deciding which tests have to be automated plays an important role in achieving successful and efficient test automation. As a leading automation testing company, we usually follow the set of guidelines listed below for making this decision.

The type of tests that would benefit from automation.

  • Repetitive tests that demand a lot of manual effort.
  • Tests that are prone to human errors.
  • Tests that should be executed on multiple platforms, hardware, or OS setups.
  • Constant tests that will not undergo frequent changes.
  • Tests that have to cover numerous builds or versions.
  • Heavy tests that require numerous data sets and large amounts of data to execute.
  • Tests that utilize frequently used functions.

Identify an Automation Testing Framework:

The next automation testing best practice involves identifying and choosing the right testing framework for your needs from the long list of automation testing frameworks that are available in the market. The framework you choose should be suitable for the technology that will be used to develop the app and the intended platforms that you are planning to run the tests on. It should also align with your testing strategy and goals. The cost of the automation framework is also a crucial factor to consider. The open-source options do have an edge over the commercial tools in terms of pricing and the constant improvements that happen due to various community contributors.

Pick the Right Automation Testing Tool:

Using the right automation testing tools is one of the test automation best practices as it will definitely have a huge impact on the success rate of your automation. So be clear as to what your need is and identify a list of tools that you could use and then choose the right tool for you. Since there are a lot of open-source automation tools, proper R&D will be needed before you directly implement a tool in a project without much knowledge. Here are a few factors to consider when choosing the right automation tool for your needs.

  • The type of application being tested is the first focus point. If you have to test a web-based app, you can opt for Selenium for automation as it is one of the most popular web app automation testing tools. Likewise, if you are looking to test a mobile app, you can choose Appium to fulfill all your automation needs with the least effort.
  • If choosing the right automation tool for your needs is crucial, so is choosing the automation tool that will suit your testing team. The most well-known languages utilized for automation testing are Java, JavaScript, Ruby, C#, and so on. Based on the language your team is comfortable with, you can pick the automation tools.
  • The cost will definitely be a deciding factor as not all will have the provision to opt for commercial solutions. So you should also consider the financial plan and requirements before choosing the automation tool for your project. Selenium and -Appium are some of the best examples of open-source automation testing tools.

Execution Plan:

Once you have the right automation framework and tools, developing an effective execution plan is the next challenge. So let’s focus on the process to create an execution plan that defines all the everyday tasks and methods related to automation.

  • The test cases have to be executed using pipelines like TEXTJenkins, TeamCity, Bamboo, and so on. By doing so, you will ensure that regression tests will either run as a component of a build/deployment event or at a time of your choice.
  • Parallel text execution is a great approach that can enable the input from the regression tests to reach the development team as quickly as possible.
  • Though you can never test a product excessively, the combination of effective test automation, solid test cases, and planned/controlled execution will assure constructive outcomes.

Allocate tasks based on skill:

Allocating tasks based on your team’s skill set is also a part and parcel of your execution plan. So allocating test cases and tasks based on their technical skill is also one of the test automation best practices. As stated earlier, 100% automation is not possible. You might have a team member who is excellent when it comes to automation. But if you assign a manual task to that person, you will be wasting a lot of potential. Likewise, the resource might have to be fluent with a certain automation tool to perform the tests. So ensure that the resource you are allocating the task to has the skills to handle it.

As a pioneer in the software testing industry, we always make sure to have a well-balanced software testing team that can handle any type of challenge. But allocating the tasks alone isn’t enough as the team members should be clear of their goals and objectives to perform as expected. So make sure that you define the need clearly to your entire team.

Release Control:

No matter how well your pipeline is developed, there will come a moment where the group needs to decide if they should deliver a build or not. Though parts of this decision-making can be automated, various parts of it will definitely require human intervention. So it goes without saying that the release control should be a seamless blend of both algorithm results and manual decision making.

  • Since the outcome of the automation tests is integral to the delivery choice, you can either opt to release if all the regression tests pass or have an experienced tester endorse the outcome before release.
  • Include the application logs of all the regression test cases that have been executed as a factor when deciding to release. But make sure that your regression tests have great test coverage as those logs will reveal blunders that go beyond just the UI issues.

Failure Analysis:

Finally, in this list of the test automation best practices, we will be exploring failure analysis. Since test cases are prone to failure, you must analyze the failing test cases and identify the root cause behind their failures. You should also make the necessary arrangements to resolve the detected bugs and issues. By doing so you will be able to greatly reduce the time it takes to fix the bugs once they have been identified by the testers. So by having a clear-cut cycle, you can prevent unnecessary arguments and have them focus on fixing the issues by using all their resources.


We hope you have found this blog to be informative and encourage you to implement these test automation best practices in your projects as well. Though different automation projects might have their own unique challenges, these test automation best practices are a great place to start. Being a top automation testing company, we understand that it is not just being the first to the market. Rather, it is about using automation to enhance product quality.

A Complete List of Selenium Commands with Examples

A Complete List of Selenium Commands with Examples

Selenium is a free and open-source testing tool that automates website testing. It is not a single tool, but rather a set of four components known as Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid. Selenium offers a number of features to testers as it provides support for multiple browsers, parallel testing capabilities, and execution on multiple machines. Since it is one of the best automation solutions in the market, we, as a leading QA company have created this blog by compiling the best Selenium commands (Inclusive of Selenium 4) one would have to know to achieve successful automation.

Selenium Commands and its types

The Advantages of Selenium WebDriver

  • Selenium WebDriver is compatible with prominent programming languages such as Java, C#, PHP, Ruby, Perl, Python, and.Net.
  • It supports cross-browser interoperability which allows you to test on a variety of browsers including Firefox, Chrome, Edge, and Safari.
  • Tests can be run on all major operating systems such as Windows, Mac, Linux, Android, and iOS.
  • Selenium WebDriver overcomes Selenium v1’s limitations such as file upload, download, pop-ups, and dialogue barriers.

The Disadvantages of Selenium WebDriver

  • Despite the many disadvantages, it is not possible to generate detailed test reports.
  • It is also not possible to test images.

Types of Selenium WebDriver Commands

Selenium WebDriver commands are the methods used to run Selenium test automation scripts. The Selenium WebDriver commands offer different ways to interact with the WebDriver and perform various tasks. These methods are accessed by using a driver variable and calling “driver.methodName().” Let’s first list out the different categories of the Selenium WebDriver commands and then explore how to use them in the different browsers.

Browser Initialization

So we’re starting the list of the best Selenium Commands with the one that is used to initialize a browser by helping us choose the browser we want to use for automating the script. The commonly used Selenium commands for browser initialization are,

Mozilla Firefox Syntax
System.setProperty("webdriver.gecko.driver”,”//driver- location/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
Google Chrome Syntax
WebDriver driver=new ChromeDriver();
Edge Syntax
System.setProperty(“webdriver.edge.driver”,” //driver-location/edgedriver.exe”);
WebDriver driver=new EdgeDriver ();

Browser Commands

Now that the browser has been initialized, the next course of action will be to perform operations such as opening, closing, retrieving page source, and so on. So let’s take a look at the various browser commands that can be used to achieve all this.

get(String args)

The above Selenium command launches a new browser window and navigates to the specified URL. The command accepts a single string type parameter, which is usually the URL of the application under test. If you are a user of Selenium IDE, you may notice that the command is similar to the IDE open command.



As the name suggests, this Selenium command gives us the URL of the page currently loaded in the browser.


String url = driver.getCurrentUrl();

If you want to retrieve the title of the currently opened web page, you can use the above command.


String j = driver.getTitle();

The above command will help you to get the source of the last loaded page and also to verify if a particular content is present or not by using the contains method.


String j=driver.getPageSource();
boolean result = driver.getPageSource().contains("String to find");

If you’re looking to return the run time class name of the object, you can use the above command to get it done.



It creates a new browser window with a new web page. It takes a String parameter and returns a void value.



If you want to test by seeing how the page reacts to being refreshed, you can use the above command to refresh the current window.



Back is a commonly used navigation action that you can achieve by using this command to go back to the previous page that you visited.



Similar to back, the forward action is also a widely used navigation action. So you can use the above command to redirect to the page you were in before clicking on the back button.


driver.navigate().forward ();

The close() command is used to close the currently open WebDriver-controlled browser window. If the current window is the only active window in WebDriver, the browser will also be closed.



There is a minor distinction between the quit() and close() methods. The quit() method terminates all open browser instances, whereas the close() method terminates only the current browser instance.



Web Elements Commands

So now we know how to open the browser and perform various browser actions, let’s progress to the Selenium commands that can be used to identify and perform actions on WebElements like text boxes, radio buttons, checkboxes, and so on. WebElements are integral to automating test scripts.

Text Box Commands


We start the list with click() as it helps us to click the textbox initially.



Entering text in a text box is one of the basic functionalities and you can do so by using this command.



If you enter text, you’ll also have to clear it at times. You can clear the value in a textbox by using the above command.



You can employ the above command to determine the relative position of an element on a web page. You can either use it to get a location of a particular element or to access the textbox area using the coordinates.

(i)To get the location of a particular element

org.openqa.selenium.Point location;

(ii)Through org.openqa.selenium.Point we can access the textbox area using coordinates


If you’re in need of retrieving the height and width (i.e) the dimensions of an object, you can use the above command.


Dimension dimension=driver.findElement("GmailAddress")).getSize();
System.out.println("Height of webelement--->"+dimension.height);
System.out.println("Height of webelement--->"+dimension.width);

You can use the above command to view the value type in a search text box.



If you’re looking to retrieve the inner text of a particular web element that is not hidden by CSS, this command can be used.



Radio Button/Check Box Commands

Radio Buttons and Check Boxes are the next web elements that we are going to see the Selenium commands for.


The click() command can be used to click the radio button or check box.



If you’re looking to verify if they have been selected or not, you can make use of this command.



You can even verify if these web elements are visible or not using the above command.



The isEnabled() command can be used to check whether the web elements are enabled or not.



You can use the above command to return the tag name of these web elements.



If you’d like to return the inner text, you can opt to use the above command.


String  str=element.getText();

The Dropdown Box and Button Commands can be used to perform operations on the Dropdown so that we’ll be able to automate the process of selecting the required field from the dropdown.

Select class

The select class can be used to work with the dropdown elements as you’ll be able to choose the option using the various Selenium commands.


Select sel=new Select(driver.findElement(By.xpath("XPATHVALUE")));

If you would like to know the number of options in a dropdown, you can use this command.


int count=sel.getOptions().size();

You can return the first selected value using the above command.


String str=sel.getFirstSelectedOption().getText();

But, if you want to return a number of selected options, you’ll have to use this option.


int count=sel.getAllSelectedOptions().size();

But what if the dropdown isn’t made for multiple options? So the isMultiple() command will come in handy as it returns true if the element supports multiple selecting options at the same time.


Boolean boolean=sel.isMultiple();
Deselect the options

You can even deselect the options you have selected using the above command.


The click() command can be used to click the element.



Finally, you should be able to automate the action of submitting the form using this command.



Windows Commands

So the next step in attaining effective automation would be to automate the actions across different windows of the browser. So let’s find out how to switch to another window, pass the driver instance to another window.
Note: In order to switch to another window, we have to first identify the tab we want to switch to.



You can obtain the name of the current window by using this command as it will return the alphanumeric name of the current window.


String  handle= driver.getWindowHandle();

If there are multiple windows open and you want to retrieve the names of numerous window handles, you can utilize this command.


Set<String> handle= driver.getWindowHandles();

You can even find out how many windows are currently open using this command.


int count=driver.getWindowHandles().size();

The above command can be used to switch to the alert window.



You can use this command with the previous command to switch to the alert window and accept the alert.


sendKeys(String stringToSend)

If you’re looking to enter a specified string pattern into the alert box, you can use this command.



You can even retrieve the string content of the alert by using the above Selenium command.


String str=driver.switchTo().alert().getText();

Taking a screenshot is a crucial part of the automation process and you can achieve it by using this command.


WebDriver driver = new FirefoxDriver();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

Frames Commands

Frames Commands are those that can be used to perform operations on the frames as it helps us to switch from one frame to another and also perform actions on the particular frames.


As the name suggests, you can use the above command to switch to another frame.



If you would like to go back to the current window from any frame, you can employ this command.



When it comes to switching to the parent frame, you can use the above command.



The above command can be used to switch to an iframe.



Actions Commands

In general, the methods of the actions classes are divided into two categories:

  • Mouse-Controlled Actions
  • Actions on the Keyboard

The Actions class has a number of methods that will return an action object unless otherwise specified. Mimicking a real user’s actions is impossible to do without automating the mouse and keyboard actions. So let’s take a look at how to do it.


The build() is a very important command that can be used to generate a chain of actions that you want to perform.


Actions action = new Actions(driver);
WebElement  e= webdriver.findElement(By.linkText(“XPATH"));

This command is used to click at the current mouse location.


Actions action = new Actions(driver);

If you would like to click and hold on to it at the current mouse location, you can do so using this command.


<Script Code>
contextClick(WebElement onElement)

Context-click is nothing but clicking the right mouse button at the current location.


Actions action= new Actions(driver);

If you hold on to the click, you’d have to release it at some point and you can do so by using this command as it releases the depressed left mouse button at the current mouse location.


Actions builder = new Actions(driver);
WebElement canvas = driver.findElement("tutorial"));
Action dragAndDrop = builder.clickAndHold(canvas).moveByOffset(100, 150).release(canvas).build().perform();

Another common mouse action is the double-clicking process and you can perform that by using this command.


Actions builder = new Actions(driver);
WebElement canvas = driver.findElement("tutorial"));
Action dragAndDrop = builder.clickAndHold(canvas).moveByOffset(100, 150).release(canvas).build().perform();
dragAndDrop(WebElement source, WebElement target)

Drag and drop is performed by clicking and holding the source element and then moving to the target location to release it. You can achieve this by using the above command.


Actions action= new Actions(driver);
WebElement Source=driver.findElement("draggable"));  
WebElement Target=driver.findElement("droppable"));  
act.dragAndDrop(Source, Target).build().perform();
dragAndDropBy(WebElement source, int xOffset, int yOffset)

This command is similar to the regular drag and drop, but it differs in the way that the movement happens with reference to a defined offset.


act.dragAndDropBy(From, 140, 18).perform();
here 140,8 are the x and y offset of target element.
moveByOffset(int xOffset, int yOffset)

You can offset the mouse’s position by either keeping the current position or (0,0) as the reference.


Actions builder = new Actions(driver);
WebElement canvas = driver.findElement("tutorial"));
Action dragAndDrop = builder.clickAndHold(canvas).moveByOffset(100, 150).release(canvas).build().perform();
moveToElement(WebElement toElement)

You can even move the mouse to the middle of a web element by using this command.


Actions action = new Actions(driver);
moveToElement(WebElement toElement, int xOffset, int yOffset)

You can use the above command to move the mouse to an offset from the top-left corner of the element.


Actions builder = new Actions(driver);   
builder.moveToElement(knownElement, 10, 25).click().build().perform();

You can perform the actions without having to call the build() command first.


Actions action = new Actions(driver);

The above Selenium commands can be used to perform single key presses and key releases.


Actions action = new Actions(driver);

Synchronization Commands

We’re almost done with all the respective Selenium commands that one will need to complete their automation. Imagine an action such as a page reloads or a form was submitted, the script would have to wait for a certain amount of time to ensure the action has been completed. That is where the Selenium commands for Synchronization come into play.


This command is used to pause for a defined time. Time is defined in milliseconds for this method.



By using the above command, the script execution will wait for a specified amount of time before it moves on to the next step.


driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

But since setting a specified amount of time for every single command is not that efficient, you can make use of this command to be adaptable by waiting for certain conditions to be satisfied. This can be achieved by using different types of ExpectedConditions.


WebDriverWait wait = new WebDriverWait(driver, 10);

Note: WebDriver Wait statements can be very useful for effective scripting as we can avoid using the Thread.sleep() Selenium commands.

Now let’s explore the various expected conditions.


You can wait until an element to be located becomes visible using this command.


wait.until(ExpectedConditions.visibilityOfElementLocated(“XPATH VALUE"));

This command can be used to wait for an element to become visible and clickable.


wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“/XPATH VALUE”)));

By using this command, you’ll be able to make the execution wait until an element has a certain string pattern.


wait.until(ExpectedConditions.textToBePresentInElement(By.xpath(  XPATH VALUE”), “text to be found”));

If you want the execution to wait until an alert box appears, you can use this command.


wait.until(ExpectedConditions.alertIsPresent()) !=null);

You can even wait for a page with a specific title using this command.



The above command can be used to wait for a frame to become available and for the control to switch automatically.


wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(“XPATH VALUE”)));

This command allows you to control two important aspects

(i) The maximum amount of time to wait for a condition to be satisfied along with the frequency at which to check if the condition has been satisfied or not.

(ii) You can even configure the command to ignore specific types of exceptions whilst waiting.


Wait wait = new FluentWait(driver);
withTimeout(30, SECONDS);
pollingEvery(5, SECONDS);

Selenium 4 Commands

So all the above Selenium commands that we saw were from Selenium 3. Now, with the launch of Selenium 4, some more commands have been added and some changes have also been implemented to the Selenium 3 commands. Since we are focused on providing the best Selenium testing services to all our clients, we are always on a path of continuous learning. So let’s take a look at all the major changes one by one.

Relative Locators

There were no techniques (or particular methods) in Selenium 3 to locate Web Elements relative to the surrounding components. But relative locators have been introduced in Selenium 4 to make it easier to locate Web Elements based on their visual placement on the UI relative to other DOM elements.


This command is used to identify the required web element that is just above the specified element.


WebElement ele1;
ele1 = driver.findElement("123"));

Likewise, to identify the required web element just below the specified element, the above command can be used.


WebElement ele1;
ele1 = driver.findElement("123"));
String ele2 = driver.findElement(withTagName("AYZ").below(ele1)).getText();

Similarly, this command can be used to identify the required web element to the left of the specified element.


driver.findElement( withTagName("ABC").toLeftOf(ele1)).getText();

Finally, the above command can be used to identify the required web element to the right of the specified element.


driver.findElement( withTagName("ABC"). toRightOf (ele1)).getText();

You can even identify required web elements that are about mexa piles away from the specified element.


driver.findElement( withTagName("ABC"). near(ele1)).getText();
Window and Tab management

It is very common for a link to open in a new tab or window based on the link you click or how you open it. We had to use the switch operation and the windowHandle function in Selenium 3 to handle it. But Selenium 4 now includes a new API called newWindow, which allows users to create and switch between new windows/tabs without having to build a new WebDriver object.




We hope you have found our comprehensive list of all the prominent Selenium Commands and their syntaxes to be useful. We have also made sure to add the commands from Selenium 4 to make this a conclusive blog that captures all the needs. These are the Selenium Commands that we use in our automaton testing scripts and hope you’ll use them in your scripts too.

The Must-Know Selenium Best Practices for Successful Test Automation

The Must-Know Selenium Best Practices for Successful Test Automation

Over the years, Selenium test automation has become an integral part of quality assurance. Despite its immense popularity, many might have faced various difficulties in the form of flaky and unstable tests. But does that imply that the issue is with Selenium? Being a leading test automation services provider, we have no second thoughts in its capacity and can firmly say that everybody can get the best out of it if they follow the best practices. Though there are no specific rules for creating your Selenium test automation scripts, these Selenium best practices will definitely act as effective guidelines. So in this blog, we have listed the Selenium best practices that one can follow to enhance the efficiency of their Selenium Test Automation.

Know Which Tests Should Be Automated

It is a well-known fact that 100% automation isn’t possible. So trying to automate every single scenario or automating every scenario that can be automated is not the best approach. So before you kickstart your automated browser testing, make sure you are clear of what tests have to be automated. When it comes to automation, always keep in mind that just because you can do something doesn’t mean that you should do it.

So start off by designing effective test cases before you start working on automation. Apart from that, analyzing if automating a scenario will result in the reduction of repetitive and tedious tasks is also crucial. So if you automate a test case that doesn’t have much frequency of occurrence, then spending that much time and effort on automating the test case is not validated. So as a first step, look for static test cases that have predictable outputs.

Choose the Best Locators

Since Selenium has a wide range of web locators available, choosing the best locators can impact the quality of your Selenium test automation. Some of the most often used web locators in Selenium WebDriver are

  • ID
  • Class
  • tagName
  • Name
  • Link text
  • XPath
  • CSS Selector
  • DOM Locator, and so on.

It’s important to pick the proper one as it will reduce the impact of user interface changes during testing. For example, if there is a dynamic scenario, link text will generally be preferable. But if you are looking for web locators that are less brittle, ID, Class, or Name would be the way to go even though it isn’t that user-friendly.
To learn more about the many ways to locate web elements and to know which locators are most suited for specific scenarios, read our blog about the different XPath methods in Selenium.

Utilize time-efficient approaches

It is not always about getting the script to work as your test scripts should also be efficient when executed. What might feel like just a few seconds will definitely have huge impacts when you have to execute the tests numerous times in different combinations. That is why we have incorporated the following Selenium best practices that will help you save loads of time.

Use Selenium Wait Commands Instead of Thread.sleep()

Various factors like network slowness or server issues can cause your web application to take additional time to load. So your automation scripts should be able to wait for all the elements to load before starting the test execution.

The Thread.sleep() method can be used for this purpose as it can pause your script for a specific amount of time.


Sleep() waits for the number of seconds supplied in the brackets, regardless of whether the working page is ready.

There is a major flaw with this function as the script will wait for a fixed time for every scenario irrespective of the need. For example, let’s assume that you have set the sleep time to be 6 seconds. But what if the webpage that has to be tested loads in just 3 seconds? Or what if the webpage took 7 seconds to load? You will either be wasting time or getting inaccurate results because of this approach. But you can prevent such issues by utilizing implicit or explicit waits.


Explicit: The code execution is halted until a certain condition is satisfied.

Packages to import to use the Explicit wait


Code to initialize a Wait Object using WebDriverWait Class

WebDriverWait wait = new WebDriverWait(driver,10);

Here WebDriverWait is the class, and new is the reference variable. It will either for the defined amount or for the expected condition to be fulfilled. This is just a sample and you can use the same concept with the other available expected conditions. Though there are various options, we have listed a few below,

  • visibilityOf()
  • alertIsPresent()
  • titleContains()
  • textToBePresentInElement()
  • invisibilityOfTheElementLocated()
  • elementSelectionStateToBe()
  • elementToBeClickable()
  • presenceOfAllElementsLocatedBy()
  • frameToBeAvaliableAndSwitchToIt()



By now you would have understood why we have included the usage of the wait commands in our list of Selenium best practices. Beyond the explicit wait, there are also implicit and fluent wait commands that give you more options. So let’s explore them now.

Implicit: The WebDriver is advised to keep polling the DOM until the element search is complete. By default, the time is set to 0.


driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Fluent: It waits for a specified maximum amount of time for a specific condition. What makes it different is that it will validate the element at regular intervals before throwing “ElementNotVisibleException”.


Wait wait = new FluentWait(Webdriver_Reference)
.withTimout(timeOut, SECONDS)
.pollingEvery(timeOut, SECONDS)
.Ignoring(Exception class)

Sample Snippet

We have mentioned a sampe snippet that will wait for 30 seconds and check the condition every 5 seconds.

FluentWait wait = new FluentWait(driver);
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
WebElement element = wait.until(new Function<WebDriver, WebElement) {    
    public WebElement apply(WebDriver driver) {    
        return driver.findElement("element"));    

Implicit: The WebDriver is advised to keep polling the DOM until the element search is complete. By default, the time is set to 0.

Use Assert and Verify-in Appropriate Scenarios

Let’s assume that there is a task to transport 100 boxes of apples to the market. But what if all the boxes of apples are rotten already? Will there be any use in putting all the effort and time to get the apple to the market only for it to go unsold? Likewise, there will be various scenarios where there are hard fails that will compromise the rest of the execution. Please keep in mind that Asserts should only be used if you want to stop the test execution when a hard failure occurs. If the assert condition is false, the execution will come to a halt, and no more tests will be run. So it is important to identify such bottlenecks and ensure that you use Asserts to save time.

If we take an e-commerce site as an example, such scenarios might come at the very beginning where a user is unable to login, or even in between where the user isn’t able to add any product to their cart. If these functionalities fail, there will be no point in testing the search functionality or payment process as it would all fail due to their dependency.

If the errors are not that critical, then you will be able to run the tests irrespective of the verify’s condition.

Increase Test Coverage

There is just no easy workaround when it comes to testing a website or an application across a variety of devices and browsers. The devices are further split based on the operating system they use as well. So let’s take a look at a few Selenium Best Practices that will help you increase the test coverage.

Browser Compatibility Matrix

Just like knowing what to automate, it is important to figure out the high-priority combinations that are used by your target audience. So create a Browser Compatibility Matrix by performing a product analysis to obtain detailed insights. Trying to perform automation testing with Selenium without narrowing down your target will not only be a cumbersome task, but it will also be a waste of time and resources.

Make use of Parallel Testing in Selenium

Though you are able to narrow down the device combinations, you will not always have the time to test everything one by one. Since Selenium’s parallel testing option is a major reason for its popularity, you can employ it not just to save time, but to also improve your test coverage in an efficient way. Almost all major test frameworks, such as PyTest, PyUnit, TestNG, Cucumber, and so on support simultaneous testing on a Selenium Grid. If you are not familiar with the concept of creating a Selenium Grid for distributed execution, make sure to read our conclusive blog.

Being the innovators we are, we even developed an open-source tool called VisGrid that will provide you with a UI to easily start a Selenium Grid, create & attach nodes, and so on.

Use many driver implementations instead of a single one

Since Selenium’s WebDrivers are not interchangeable, executing automated cross-browser tests on a local computer is not the same as running them on a continuous build server. It would be a mistake to assume that the following test will utilize Firefox WebDriver in that situation (or Chrome WebDriver or any other WebDriver).

When running integration tests in a continuous build environment, the test will only get a RemoteDriver object (i.e., WebDriver for any target browser). Using parameter notes to manage multiple browser types and prepare the code ready for simultaneous execution is one of the Selenium best practices (or parallel testing). LabelledParameterized (@Parameters in TestNG and @RunWith in JUnit) may be used to build small frameworks in Selenium.

Ease Code Maintenance

When working on automation tests with Selenium, it’s critical to pay attention to the test code’s maintainability and reusability. As one of the best test automation companies, we always make sure our scripts are easy to maintain by implementing the following Selenium best practices.

Use design principles and patterns, such as the Page Object Model

With the ever-increasing client expectations, a website’s user interface (UI) will inevitably change as new updates get introduced at regular intervals. So the locators for certain UI components will vary as well. This implies that QAs have to once again create new test cases for the same page or make numerous changes at various places of the script, which can be time-consuming.

So you can employ the Page Object Model design pattern to create test scripts and overcome this issue. In this approach, each web page is considered a class file in the design pattern, and each class file contains related web components.

This method greatly increases the reusability of the code while also making test maintenance easier. Read our complete guide to page object model in Selenium before you implement it.

Quarantine flaky tests

If a test keeps failing at random even if the code hasn’t gone through any changes, then it is called a flaky test. Since the testers can never be sure of the results, they will lose trust in the code and end up re-running the scripts, or debugging the scripts even though there might not be an actual defect. So make sure to quarantine such tests from your other tests. Once they are separated, make sure to analyze them and fix them before you bring them back to your test suite as flaky tests can disrupt your entire automation test suite with false positives and negatives.

Wrap Selenium Calls

You might be using various web locators such as XPath and ID to locate different web elements on the page. So the code that is regularly used in the implementation should be separated into its own API to reduce code duplication. By following this approach, you will be able to reduce the code size and enhance maintainability.

Use a standardized directory structure

Page Objects, Helper functions, and file(s) that include web locator information needed in test scenarios may all be found in the Src folder. The actual test implementation can be stored in the test folder.
When it comes to a directory structure for Selenium test automation, we don’t have a common guideline. Selenium best practices, on the other hand, proposes that we have a directory structure that isolates the test implementation from the test automation framework. This improves the test code’s structure.

Implement Data-Driven Testing for Parameterization

Hard coding test values in test automation scripts are extremely troublesome and not scalable in any way. But you can avoid the various disadvantages like code duplication by implementing data-driven testing by using Parameterization. It aids in the execution of test cases that have a variety of inputs (or data sets).

Naming Convention

Improper naming of your web elements in your automation script could lead to a lot of unnecessary confusion. You may not face any issues as long as you are the only person using the script, but you have to ensure that your script can be used by anybody. Effective naming eases code maintenance by also making it easier to find the web element you are looking for in your code. Now let’s see a few tips that can help you.

1. Add prefixes to the name of your web elements as shown in the below table as it describes the type of web elements being used. In addition to that, you can name the web element based on how it appears in the UI.

S. No Web Element Type Prefix Example
1 Text Box Txt TxtUsername,TxtPassword
2 Button Btn BtnSignUp , BtnLogin
3 Drop Down Dd DdCountry , DdYear
4 Select Drop Down Sdd SddMonth , SddYear
5 Check Box Chk ChkGender, ChkLanguage
6 Header Hdr HdrName, HdrUser
7 Table Tbl TblBooks, TblProducts
8 Label Lbl LblUserName, LblPassword
9 Image Img ImgProfile, ImgCart

2. You can even add prefixes that denote the action to be performed on the web element.


S. No Action Prefix Example
1 Click Clk ClkLogin, ClkIcon
2 Type Set SetMobileNo, SetPassword
3 Verify Verify VerifyLogo
4 Check A Check Box Chk ChkLanguage
5 Select Value From Drop Down Select SelectCountry, SelectZone

3. Likewise, you can make use of suffixes when creating action pages.




4. To make it even clear, you can use a camel case to name the web elements.

Camel case is nothing but a typing convention like lower case and upper case in which the first letter of every word is capitalized.


If a text box has the label as “Email address”, name it as “txtEmailAddress”

Proper Documentation

Creating proper documentation for your automation tests in Selenium is as important as any of the other Selenium best practices we have discussed thus far.

Use Automated Screenshots to Analyse Failures

Automation Test Script running into failures is an eventuality. But we will not be sure if the failure is due to a defect in the Application Under Test (AUT) or if there is a problem with our code. So analyzing the cause of a test failure will be very crucial, and so taking screenshots is a best practice that can save a lot of time. Screenshots are not just great for failures as you can make use of screenshots as evidence for success.
To capture a screenshot, use the getScreenshotAs function in the following code sample.

File source = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("Test Screenshot.png"));

Log and Report

Finding that one failed test case in a large test suite is like finding a needle in a haystack. So using console logs at suitable points in the test code helps us understand the issues better and zero in on the core problem.
Debug, info, warning, error, and critical are some of the common log levels that are available in most programming languages. Since adding unnecessary logs to the test implementation might cause test execution to be delayed, it is better to add logs with level errors in scenarios that enable easier tracking.

Like logging, reporting is also an important aspect of Selenium test automation as it helps determine if the test has passed or failed. You can also keep track of the progress of test suites (or test cases). This in turn helps improve the readability of the output and helps you reduce the amount of time spent maintaining test data as you can easily analyze the features and test coverage.

Set Zoom Level to 100% and Maximize the Window

Make sure to set the zoom level in your browser to 100% during your automation as it is one of the basics that should be followed regardless of which browser you opt to use. It will both provide a native mouse experience and ensure that the native mouse events are assigned to the proper coordinates.

Ensure to maximize the window as soon as the test URL is loaded as Selenium doesn’t launch the browser in the maximized mode by default.




We have seen great results by implementing these Selenium best practices in our automation testing projects and hope you will them useful in the future as well. We had listed various Selenium best practices under particular categories to enable a crystal clear understanding of how each of them impacts the testing process on the whole. So we hope you have enjoyed reading our blog and found the content to be informative as well.

The Different XPath Methods in Selenium : Getting Started with Automation

The Different XPath Methods in Selenium : Getting Started with Automation

Object locating technique is one of the fundamental when it comes to automation testing. If we test the application manually, we would interact with various objects or elements like links, buttons, radio buttons, lists, text boxes, sliders, and so on. So for us to mimic an actual user, the automation tool would also have to perform the same actions, and locating the objects that have to interact with is the first goal. Once the object is located, we can perform the desired actions like clicking on it, entering text, and so on. Selenium is one of the prominent automation testing tools and it uses the concept of ‘Locators’ to identify the elements/objects. So let’s take a look at the Different XPath Methods in Selenium as they are the building blocks of any Selenium automation script.

Steps to find elements in DOM:-

Before we head over to explore the Different XPath Methods in Selenium, let’s also look into a few basics like the ways to find elements in DOM and the different locators that exist in Selenium.

1. First and foremost, you have to open the website that you want to automate. Once it has loaded, click on the ‘F12’ key to open DevTools. As shown in the below image, click on the inspect icon to enable it and then click on the element you want to inspect.

Finding Elements in DOM - Step 1

2. There are also other ways to open the developer’s tools. You can either click on the ‘Menu’ option in the browser, click on ‘More Tools’ under that, and then click on the ‘Developer tools’ option that is shown.

Different Types of Locators - Step 2 in Finding Elements (1)

3. If not you can just right-click on the element you want to inspect and click on the ‘Inspect’ option to locate the element.

Step 3 - FInding Elements in the DOM 1

Step 3 - Finding Elements in DOM - Types of Locators (1)

Different Types of Locators in Selenium:-

Now that we know the ways to open Developer tools in our browser, let’s take a look at the different types of locators that can be used to identify the various web elements.

  • ID
  • Name
  • LinkText
  • Partial LinkText
  • CSS Selector
  • Xpath

ID Locator:-

ID is the first choice for many testers as it is one of the safest and fastest locators that can be used to find the location of an element. What makes ID so effective is that it is unique for each element on the web page, making it easily identifiable. IDs are mostly account numbers, university roll numbers, usernames, passwords, and so on as they will be unique.

Name Locator:-

If you want to locate an element that doesn’t have too many elements with similar names, you could use the name locator as it is also an effective way to locate an element. If we take a form to be an example, you might have various text fields and one submit button. So locating text fields using the names can be hard. But since there is only one submit button you will be able to locate it without much confusion. If at all there are two or more elements with the same name attribute, then the first element with the value of the name attribute will be returned. If at all there are no elements that have a matching name attribute, then a NoSuchElementException will be raised.


Of the Different Types of Locators in Selenium, there are two locators that can be used to locate hyperlinks on a webpage. So let’s say you want to verify if a link is working correctly on a page. You can make use of linkText to locate that hyperlink by using the exact match of the string.

Partial LinkText:-

The main distinction from the LinkText in Selenium to the Partial LinkText is that it doesn’t investigate the specific match of the string. So it will even be able to identify fractional matches. This will come in handy when you have to search hyperlinks that have a high text length.

CSS Selector:-

What if you have to locate complex elements on the page? The CSS selector will be the best choice for you. The only downside with CSS identification is that it is not supported by all browsers. But it may not be a huge concern as it is supported by all the widely used browsers like Google Chrome, Mozilla Firefox, Safari, Opera, and so on.


XPath stands for XML path language. It is based on the tree model of XML documents and provides the ability to navigate around the tree by selecting nodes using a variety of criteria. Though XPath locators are reliable, they are slower in comparison to the CSS Selectors. XPath is also supported by all the major web browsers. Now, let’s take a look at the different XPath methods and their syntaxes.

The Different XPath Methods in Selenium:-

basic xpath – To select a node based on the attribute,


//tagname[@attribute =' value']

contains – We can use partial text to find an element,



using OR – The element will be located if any one condition or both conditions are true.


//tagname[@attribute='value' or @attribute ='value']

using AND – The element will be located only if both the conditions are true,


//tagname[@attribute='value' and @attribute ='value']

starts-with – This can be used in a webpage where the attribute value changes on refreshing the page or due to dynamic operation on the page as it will locate the element with the starting text alone,



text() – It is an inbuilt function used to locate the element based on the text of the element,



axes – Can be used to locate elements that are more complex and dynamic by following various methods like following, parent, child, and so on.

Locating Techniques:-

Knowing the Different XPath Methods in Selenium is the first step, but employing them in an effective manner to get the job done is the key. As a leading automation testing company, we make use of some of the best locating techniques that have made our job easy. So let’s explore them now.

1) To find an element using the last and position keywords

//input[@type='text'][position()=1 or position()=last()]

To find an element in Locating Techniques

We can get the first and last element inside a div tag using the position and last keywords.

2) To locate an element with the keyword count


To locate an element - Different types of locators

We can locate an element by the count of another element. In this example, we have located the div tag by the count of its child input tags (i.e.) 2.

3) To identify an element with the parent keyword


To Identify an element

Since we can locate an element with the element of the “parent” keyword, we have located the div tag which is the parent of the input tag.

4) To locate an element with the following- sibling keyword


To locate an element with Sibling keyword

In this example, we have three input tags under a parent tag div. If you want to locate only one input tag among the three tags, we can use the following-sibling keyword to do so.

5) To identify with a single class attribute

Consider a situation where there are 4 input tags and that one input tag has a class attribute. In this case, if all the other elements for the input tags are the same, we can locate the element with the help of the Class attribute.


To Identify Single class attribute - Different types of Locators

6) Odd & Even Rows in a Table

We can even locate the elements in an odd and even row of a table by using the below commands. It will work like a filter as we will get all the elements in the even/odd rows as the result.

ODD ==> table[id=table1] td:nth-child(2n+1)
Even ==> table[id=table1] td:nth-child(2n+2)

Odd and Evens in the table

7) List of elements in a table

If you’re looking to locate a list of elements in a table by sorting them in ascending or descending orders, we can use the below technique.


List of Elements in a Table

8) The Indexing Technique

If you want to select an element inside the table, you can use this indexing technique to locate the particular element.


Indexing Technique - Different Types of Locators

9) To locate elements based on the value

We have used an example where all the elements that have a price that is less than or equal to 2 are located.

//item[price >= 2]/price

To locate an element based on the value

10) To verify if a checkbox has been checked or not

Say you want to pick out elements that have not yet been checked in a list of elements, you can use the below technique to isolate the type of elements you want.

 Here, input - tag name, good - id


We hope you found this blog to be informative as knowing the Different XPath Methods in Selenium is one of the must-know basics of automation testing. As a leading QA company, we are always keen on the knowledge and the positive mindset that is required to create swift solutions to big problems. So gaining an in-depth understanding of the various techniques will play an instrumental role in your growth as an automation test engineer. If you are not clear, then you will have a tough time figuring out quick solutions for your automation needs.

The Top Selenium 4 New Features You Should Know About

The Top Selenium 4 New Features You Should Know About

Now that Selenium 4 has been officially released, we thought it’ll be a great idea to compare the architecture of both Selenium 3 & 4 and explore the Selenium 4 New Features. As one of the leading automation testing companies, we have been using Selenium for years and years over numerous projects to deliver high-quality Automation Testing Services to our clients. We feel that the upgrades in Selenium 4 are all welcome features that will be useful in helping the software testing community. Now let’s kick start this blog by comparing the two architectures.

Selenium 3 Architecture:

Selenium WebDriver Architecture

  • The architecture for Selenium 3 includes the JSON Wire Protocol (JSON stands for JavaScript Object Notation).
  • The JSON Wire Protocol operates as a mediator to transfer information from the client to the server over HTTP (HyperText Transfer Protocol).
  • The Request is sent from the Selenium Client & the WebDriver Language Bindings module and received by the JSON Wire Protocol over HTTP. It is then secured by the Browser Driver module as shown in the above figure.
  • Therefore the request command is delivered to a Web Browser module where the real automation takes place as shown in the above figure.

Selenium 4 Architecture:

Selenium 4 Architecture

  • Selenium 3 includes the JSON Wire Protocol as discussed above, whereas Selenium 4 has introduced the W3C protocol as the communication medium of the browser between the client and server.
  • Here, the client has two parts called the Selenium Client and WebDriver Language Bindings. The Browser Drivers acts as the server as shown in the above figure.
  • The Selenium Client sends out a request to perform a command.
  • The Browser Drivers receives that request and then returns a response after an automation test script is executed on the web browser.

Selenium 4 New Features:

Now that we understand how both versions work, let’s explore what are the new features that Selenium 4 has to offer.

1. Selenium WebDriver:

It is an open-source API that the web driver allows to interact with the browser just like a real user.

2. Selenium IDE:

It enables us to record and playback the user interactions with the browser. The new version of Selenium IDE is now available with more features.

3. Selenium Grid:

It can be used to save time by distributing and running tests on multiple browsers, operating systems, and machines.

4. Using WebDriver Manager:

Prior to the release of Selenium 4, if you wanted to run Selenium WebDriver automation scripts in Chrome, you had to first download chromedriver.exe and then use the System.setProperty as shown below to set its path.


After Selenium 4 release

Step 1: Add the Maven Dependency for the WebDriver Manager

Step 2: Add the code

Instead of the “System.setProperty()” call, the class code for WebDriverManager should be used.


Step 3: We can also choose a specific version of the browser as shown below.


5. To Capture screenshot of specific web element in selenium 4:

Users being able to take a screenshot of a specific web element is another one of the best Selenium 4 New Features that can make life easier for testers. Earlier, it was possible to take a screenshot of the entire page, but there was no provision to take the screenshot of a specific web element. Though it is a simple upgrade, it can come in very handy during real-world usage.

WebElement logo =driver.findElement(By.xpath("//div[@class='logo_container']"));
File file=logo.getScreenshotAs(OutputType.FILE);
File destFile =new File(“codoid.png”);

6. To open the new tab on the browser in Selenium 4:

The users can save a lot of time as it is now possible to open a URL in a new tab along with the existing tab. Let’s take a look at the sample code for opening two URLs in two different tabs.

public class SampleTab {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();

7. To Open a new window on the browser in Selenium 4:

So it doesn’t just stop with new tabs, you can also open a new window on the same browser and access two applications at the same time in Selenium 4.

public class SampleWindow {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();

8. Relative Locators:

Selenium 4 has even added 5 relative locators that enable testers to find web elements relative to another element in the implemented DOM.

The Five locators newly added to Selenium 4:

  • toLeftOf()
  • toRightOf()
  • above()
  • below()
  • near()

The Key Differences between Selenium 3 and Selenium 4

S. No Selenium 3 Selenium 4
1 The Chrome Driver Extends Directly To The Remote Web Driver. The Chrome Driver Class Extends To The Chromium Driver That Has A Few Predefined Ways To Access The Dev Tool.
2 The JSON Wire Protocol Operates As A Mediator To Transfer Information From The Client To The Server Over HTTP. Since It Uses The W3C (World Wide Web Consortium) Standard Protocol, The Driver And Browser Communication Follows The Standard Procedure.
3 The Testers Always Have To Start The Hub And Node Jars Every Time They Perform Automation Testing. Testers Needn’t Have To Start The Hub And Node Jars Every Time They Perform Automation Testing.
Related Blogs

Selenium Plugins


So it is very evident that the Selenium 4 upgrade has a lot of good improvements to offer including better documentation. By seeing the architectural changes, we hope you will be in a better position to use the tool more effectively. As a leading QA company, we always make it a point to know the tool inside and out as it helps us utilize the full potential of the tool.