<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Riadayal</title>
    <description>The latest articles on Forem by Riadayal (@riadayal).</description>
    <link>https://forem.com/riadayal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F842342%2Fbc2811de-c2cd-40ca-95f9-879888264154.png</url>
      <title>Forem: Riadayal</title>
      <link>https://forem.com/riadayal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/riadayal"/>
    <language>en</language>
    <item>
      <title>Automation Testing Tutorial: A Starter’s Guide With Example</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Wed, 20 Apr 2022 07:29:38 +0000</pubDate>
      <link>https://forem.com/testmuai/automation-testing-tutorial-a-starters-guide-with-example-2po3</link>
      <guid>https://forem.com/testmuai/automation-testing-tutorial-a-starters-guide-with-example-2po3</guid>
      <description>&lt;p&gt;Software testing is an integral part of any IT project. Testing the software more and more will ensure a better quality of your software. Now, how do you achieve it? Either you go with &lt;a href="https://www.lambdatest.com/blog/34-ways-to-save-time-on-manual-cross-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Manual Testing&lt;/a&gt; or Automation Testing.&lt;/p&gt;

&lt;p&gt;Now sticking to manual testing can land you in trouble sometimes, as achieving &lt;a href="https://www.lambdatest.com/blog/a-breakdown-of-continuous-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Continuous Testing&lt;/a&gt; through manual testers can be really exhaustive. Moreover, manual testing is prone to human errors, is time-consuming, expensive, and can hit customer experience greatly.&lt;/p&gt;

&lt;p&gt;Businesses are constantly pressured to improve, adapt, and become competitive. Keeping up with all the changes in the technology industry is an enormous challenge, and organizations, therefore, need to automate repetitive testing processes to ensure that software performs according to expectations and provides value in no time. This can happen by adopting &lt;a href="https://www.lambdatest.com/blog/enabling-agile-software-testing-with-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;agile methodologies&lt;/a&gt; to achieve shorter development cycles and accelerated Time to Market (TTM).&lt;/p&gt;

&lt;p&gt;Having said that, in my opinion, manual testing still plays an imperative and indispensable role in the software development life cycle, though it has to be coupled with a formidable &lt;a href="https://www.lambdatest.com/blog/the-definitive-guide-to-automation-testing-for-it-teams/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing strategy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing tutorial&lt;/a&gt;, we will cover all about automation testing, the need for automation testing, and its different approaches.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/string-split-by-delimiter?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Split Your String&lt;/strong&gt;&lt;/a&gt; — A free web based utility that instantly splits text into multiple pieces. This online tool can be used to split long web addresses, texts, word, and much more. Select a delimiter and start splitting right away!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Automation Testing?
&lt;/h2&gt;

&lt;p&gt;Automation testing is the process of carrying out the test activities using the assistance of tools, scripts, and software by repeating pre-defined actions.&lt;/p&gt;

&lt;p&gt;In simple terms, you can understand automation testing as a type of testing that focuses on replacing repetitive, error-prone, and time-consuming manual tasks or activities with automated scripts in order to enhance the performance of the software and efficiency.&lt;/p&gt;

&lt;p&gt;Testing is a very crucial activity in any Software Development Lifecycle. In order to ensure a better quality of your software, you need to ensure better testing of it. Automation testing gives testers the time to focus on other quality activities like performing &lt;a href="https://www.lambdatest.com/blog/exploratory-testing-all-about-discovery/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;exploratory tests&lt;/a&gt;, analyzing test results, etc., by taking over the repetitive and mundane tasks like &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Regression tests&lt;/a&gt;. As a result, automation testing enables you to achieve better test coverage in a shorter period of time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference between Manual and Automation Testing
&lt;/h2&gt;

&lt;p&gt;Let’s see the major differences between Manual and Automation Testing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FEATURES&lt;/th&gt;
&lt;th&gt;MANUAL TESTING&lt;/th&gt;
&lt;th&gt;AUTOMATION TESTING&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Test Execution&lt;/td&gt;
&lt;td&gt;Done manually by the team members&lt;/td&gt;
&lt;td&gt;Done using automation tools and scripts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test Efficiency&lt;/td&gt;
&lt;td&gt;Time-consuming and less efficient&lt;/td&gt;
&lt;td&gt;Saves time and is more efficient&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test Accuracy &amp;amp; Reliability&lt;/td&gt;
&lt;td&gt;Low, as manual tests are prone to human errors&lt;/td&gt;
&lt;td&gt;High, as no scope of human errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrastructure Cost&lt;/td&gt;
&lt;td&gt;Low, Return of Investment is low&lt;/td&gt;
&lt;td&gt;Low (for the cloud-based test), Return Of Investment is high&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Usage&lt;/td&gt;
&lt;td&gt;Suitable for Exploratory, Ad Hoc, and Usability Testing&lt;/td&gt;
&lt;td&gt;Suitable for Regression, Load, and Performance Testing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Coverage&lt;/td&gt;
&lt;td&gt;Difficult to ensure greater test coverage&lt;/td&gt;
&lt;td&gt;Easier to achieve greater test coverage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The above differences clearly indicate the effectiveness of automation testing. However, with manual testing, you benefit from human expertise and knowledge, which an &lt;a href="https://www.lambdatest.com/automation-testing-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing tool&lt;/a&gt; can never provide a match for.&lt;/p&gt;

&lt;p&gt;Hence, an ideal approach would always be to keep a combination of Manual + Automation activities for your testing cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Automation Testing?
&lt;/h2&gt;

&lt;p&gt;Now that you have seen some of the major &lt;a href="https://www.lambdatest.com/blog/17-key-benefits-of-automation-testing-for-a-successful-release/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;benefits of automation testing&lt;/a&gt;, let’s understand the need for automation testing through a practical use case.&lt;/p&gt;

&lt;p&gt;You get a new feature to test in your software. You started your test plan, and there are some 50 test cases that you identified.&lt;/p&gt;

&lt;p&gt;You started the tests and reported some 10 bugs in the first sprint. Those bugs keep getting fixed over sprints, and you have to test the updated version of the software with each build. Now, how do you ensure that the fix for one bug doesn’t affect the older working areas?&lt;/p&gt;

&lt;p&gt;To ensure that, you need to test the complete software or perform regression testing after each bug fix. When the number of bugs in software increases or the number of features to test increases, manual testing may turn cumbersome. This is where automation testing comes in.&lt;/p&gt;

&lt;p&gt;In such cases, you can simply automate the areas you have already tested and covered. Now, every time a new build or bug fix comes in, you can run the entire suite and easily ensure the health of your software.&lt;/p&gt;

&lt;p&gt;Hence, with lesser time, you can achieve better coverage and quality of your software. An &lt;a href="https://www.lambdatest.com/blog/effective-test-automation-strategy/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;effective test automation strategy&lt;/a&gt; plays an important role in ensuring a bug-free application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXVGqzEhORHcRVNDsndEjwQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXVGqzEhORHcRVNDsndEjwQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/all-you-need-to-know-about-automation-testing-life-cycle/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation testing life cycle&lt;/a&gt; mentioned above is a group of well-defined phases that result in an efficiently working test automation framework used to develop and maintain the software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which Test Cases To Automate?
&lt;/h2&gt;

&lt;p&gt;Automation Testing has a lot of benefits and is well suitable for areas that require testing over and over again, but can we achieve 100% test automation?&lt;/p&gt;

&lt;p&gt;Well, it’s difficult to achieve 100% test automation, and hence, it’s very important to determine which test case can be automated.&lt;/p&gt;

&lt;p&gt;Let’s look at the areas where you can apply Automation Testing&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repetitive (Regression) Tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the prime candidates for automation tests, as their numbers keep on increasing with the addition of new functionalities. As a result, they become difficult to maintain, and running them manually over and over again becomes a mundane task.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complex Tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Complex tests are best to automate. For example, consider the areas which require large calculations; they are always prone to human errors. Hence, automating them would always ensure the correct result of your software.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smoke Tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The smoke tests which probably need to be carried out in different environments like Dev Env, QA Env, and Production Envs are also good candidates for automation testing. It would save a lot of time by running these tests through automation every time a new environment comes in. This way, you can also cover tests over different browsers or OS flavors in less time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data-Driven Tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the tests that require repeated testing with different data sets, and hence, automation testing can prove to be a boon in such cases.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance Tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Automation testing will help you test the software performance and load under different conditions easily and in much lesser time as compared to the manual approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do you perform Automation Testing?
&lt;/h2&gt;

&lt;p&gt;The below-mentioned steps are followed in the automation testing process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Test Tool Selection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define Scope Of Automation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Planning, Design &amp;amp; Development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test Execution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintenance&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Test Tool Selection
&lt;/h2&gt;

&lt;p&gt;Before starting with any test automation, you need to decide which kind of tests you need to automate. Once you have the test definition ready, you need to select the correct set of tools that can help you in performing those tests. There are several testing tools available. The industry-standard tools for automated testing are based on code and code-based test scripts.&lt;/p&gt;

&lt;p&gt;The most popular code-based web automation framework for automation testing is &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;, which allows you to test web applications using different browsers (Chrome, Firefox, Internet Explorer, etc.). It also supports many languages such as Java, Python, C#, etc. However, choosing the correct one is a very crucial step in an automation process.&lt;/p&gt;

&lt;p&gt;Consider the below pointers when selecting an automation tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How easy is it to develop and maintain scripts using the test tool?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How many different platforms does the tool support? For e.g., Web, Mobile, Desktops, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How many different languages is the tool compatible with?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does the tool support a reporting mechanism?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Define Scope Of Automation
&lt;/h2&gt;

&lt;p&gt;Now that you have selected the best-suited test tool, the next step is to define the scope of your test automation. Consider the below points while defining the scope of automation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The complexity of test cases&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Technical feasibility&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Common functionalities across applications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reusability and Scalability of test cases for cross-browser testing&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Planning, Design &amp;amp; Development
&lt;/h2&gt;

&lt;p&gt;The Planning, Design &amp;amp; Development phase includes the below points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Framework design &amp;amp; its features&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test case development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test suite preparation, For e.g., Smoke, Sanity, Regression&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Plugging framework with some CI/CD pipeline to achieve continuous testing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Test Execution
&lt;/h2&gt;

&lt;p&gt;The scripts developed during the design phase are now executed in this phase. Execution can be performed using the automation testing tool or the test management tool, which will, in turn, invoke the test automation tool. You should start the execution of your test scripts as early as possible. This is what the &lt;a href="https://www.lambdatest.com/shift-left-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Shift Left Testing&lt;/a&gt; approach also suggests.&lt;/p&gt;

&lt;p&gt;In contrast to traditional models like the &lt;a href="https://www.lambdatest.com/blog/agile-vs-waterfall-methodology/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Waterfall Model&lt;/a&gt;, where testing comes into the picture at the very end of the cycle, the Shift Left Testing approach suggests moving the Testing activities “Left” or rather “earlier” in the development cycle. Thus, it involves the testers much earlier in the software development life cycle. The earlier the testers are involved, the more bugs you find, and as a result, you have a better quality product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Maintenance
&lt;/h2&gt;

&lt;p&gt;In this phase of automation testing, testing is carried out in order to determine whether the newly added functionalities are working fine or not. Maintenance and up-gradation of test suites are carried out in order to improve the effectiveness of automation scripts with each successive release cycle.&lt;/p&gt;

&lt;p&gt;Many firms even use this phase for Shift-Right Testing. Shift-Right testing, or rather Testing In Production, happens after the software is deployed in production environments. This is mainly done in order to ensure the correct performance, stability, and usability of the application in the production environment.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/sorting-list?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Online Sort List&lt;/strong&gt;&lt;/a&gt; — This tool changes the order of all your list items so that they are sorted alphabetically, or numerically. Try sorting your list online now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Approaches to Automation Testing
&lt;/h2&gt;

&lt;p&gt;There are three main approaches that you can consider while performing automation testing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Code-Driven Testing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Graphical User Interface Testing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Framework Approach&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Code-Driven Testing
&lt;/h2&gt;

&lt;p&gt;This testing approach is a popular method in &lt;a href="https://www.lambdatest.com/blog/enabling-agile-software-testing-with-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;agile software development&lt;/a&gt;. Here, the focus is mainly on test case execution to determine if different sections of code are performing as per expectations or not.&lt;/p&gt;

&lt;p&gt;The idea behind code-driven testing is to use a programming language to write the unit test instead of using an external tool that provides a testing framework. The advantages are that you have full power at your disposal to create whatever tests you want, and you don’t have to deal with an external tool. The disadvantage is that it is harder to set up and run tests, so it can be more difficult to get people to do it regularly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graphical User Interface Testing
&lt;/h2&gt;

&lt;p&gt;With the increasing complexity of software and its graphical interfaces, the need for formal GUI testing has increased dramatically. The testing process can be categorized into two main types: unit testing and functional testing.&lt;/p&gt;

&lt;p&gt;Unit testing, which is most often driven by developers, involves a detailed analysis of each component of the application to ensure that it is operating correctly in isolation. Functional testing, on the other hand, determines whether or not all components of the application can be used as expected by the end user. This phase of GUI testing is usually performed by quality assurance analysts who are more familiar with how users interact with the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Automation Framework
&lt;/h2&gt;

&lt;p&gt;A framework is a set of guidelines that help in maintaining test consistency and test structure. It also helps in achieving the maintainability, scalability, and reusability of the code across test cases.&lt;/p&gt;

&lt;p&gt;There are four major kinds of frameworks used in automation testing:&lt;/p&gt;

&lt;p&gt;1- &lt;strong&gt;Data-Driven Framework&lt;/strong&gt; — These frameworks are focused on separating the logic of test cases and the test data separately. Here the data is treated as an input to the test script logic. Each data set can be treated as a separate test case.&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://www.lambdatest.com/blog/data-driven-framework-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;data-driven framework&lt;/a&gt; is a test automation framework that stores keywords and locators of elements into an external file, such as an XML file. This makes it easier for testers to build test cases because it does not require the use of object repositories.&lt;/p&gt;

&lt;p&gt;Data-driven frameworks are often used with keyword-driven frameworks. Keywords are stored in a data file and then placed into a function library. The keywords may be written manually or generated via recording. Tests are created in the data file, which can be edited by testers without programming knowledge. The test data for each keyword is stored in the same row as the keyword, making it easy to change.&lt;/p&gt;

&lt;p&gt;2- &lt;strong&gt;Keyword-Driven Framework&lt;/strong&gt; — A keyword-driven framework is essentially a data-driven framework that is limited to accepting inputs only from an excel data source. In this type of framework, test case logic resides in a database table and is linked to one or more related tables that contain the test data. Each logical operation of the application under test is defined as a keyword, which represents some action on the application under test. The keywords are then mapped to a subroutine, which implements the functionality of the keyword and performs the desired action on the application.&lt;/p&gt;

&lt;p&gt;The main advantage of this type of framework is that it does not require any programming skills because all the required operations can be performed using keywords. Therefore, anyone (even nonprogrammers) can create and execute test cases using this approach. However, this framework limits itself to operations that can be performed using existing keywords; no new keywords can be created because they would require programming knowledge.&lt;/p&gt;

&lt;p&gt;3- &lt;strong&gt;Modular Testing Framework&lt;/strong&gt; — Modular Testing Framework is a way to test a piece of software in isolation. Each module is tested with the same testing framework so that testing multiple modules can be done with a single line of code.&lt;/p&gt;

&lt;p&gt;The framework is composed of two main components: Test Cases and Test Suite. A Test Case is an object that defines a series of steps or actions to be performed. The Test Suite is simply an object that contains a collection of Test Cases.&lt;/p&gt;

&lt;p&gt;When the Test Suite is executed, it will execute each Test Case using a Test Runner object that can perform assertions on the results produced by executing the individual Test Cases.&lt;/p&gt;

&lt;p&gt;4- &lt;strong&gt;Hybrid Testing Framework&lt;/strong&gt; — Hybrid Driven Framework is a mix of both the Data-Driven and Keyword-Driven Frameworks. In this case, both keywords, as well as the test data, are externalized.&lt;/p&gt;

&lt;p&gt;A hybrid testing framework combines the strengths of two approaches, using features of both to achieve the best of both worlds. It can be especially good at handling complex, difficult-to-test situations, and requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Popular Test Automation Frameworks
&lt;/h2&gt;

&lt;p&gt;Now that we have learned the basics about test automation, let’s see some of the &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;popular test automation frameworks&lt;/a&gt; which are being widely used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2028%2F1%2AHMu_cn55NrhLy-OciClOLw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2028%2F1%2AHMu_cn55NrhLy-OciClOLw.png" alt="[https://www.tricentis.com/state-of-open-source-2020/](https://www.tricentis.com/state-of-open-source-2020/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;&lt;/strong&gt; — Selenium is a popular test automation framework used to validate web applications across different browsers and platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;&lt;/strong&gt; — Cypress is a JavaScript test automation solution used for web automation. It enables teams to create web test automation scripts. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TestNG&lt;/strong&gt; — TestNG is a powerful test automation framework for Java. It is inspired by JUnit and NUnit. It can be used to cover a wider range of test categories: unit, functional, end-to-end, integration, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;WebDriverIO&lt;/strong&gt; — WebDriverIO is an open-source testing utility for nodejs. It allows you to run Selenium tests written in JS on multiple browsers and platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pytest&lt;/strong&gt; — pytest is a testing framework based on python. It’s often considered to be the de-facto standard when it comes to writing unit tests for python code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;NUnit&lt;/strong&gt; — The NUnit Framework is a unit testing framework for all .NET languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PHPUnit&lt;/strong&gt; — PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cucumber&lt;/strong&gt; — Cucumber is an open-source tool that supports Behavior Driven Development(BDD) frameworks. Cucumber enables you to write test cases that anyone can easily understand regardless of their technical knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These were some of the popular test automation frameworks I have come across for different languages. However, the list doesn’t end here. There are a lot of other test automation frameworks also available in the market. You can check them and select one that best suits your overall requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of Test Automation
&lt;/h2&gt;

&lt;p&gt;Let us now see a basic test automation example. In this case, we will automate a web page making use of the Selenium framework and LambdaTest.&lt;/p&gt;

&lt;p&gt;Selenium is an open-source framework for cross-browser and cross-platform testing of web applications. It is a suite that allows automated tests of websites and web applications in different browsers on different platforms using any programming language of your choice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cloud testing tools&lt;/a&gt; like LambdaTest offer a &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; that lets you run parallel tests on an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser farm&lt;/a&gt; of 3000+ browsers and operating systems. All you need to do is instantiate the remote Selenium WebDriver instead of the local Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;Here’s a quick video on performing Selenium automation testing on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;End to End testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;With LambdaTest, you don’t have to worry about downloading and configuring hundreds of browsers on your machine, as they are readily available on the online Selenium Grid. Instead, all you need to do is register on LambdaTest for free, claim your 100 free automation testing minutes, and &lt;a href="https://www.lambdatest.com/selenium-ide-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;run Selenium IDE tests on cloud&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have covered the basics of cloud Selenium Grid let’s implement a sample example using LambdaTest Selenium Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;In the below example, I am running the same test case on Chrome (latest) + Windows 10 combination.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch Chrome browser on Windows 10.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest sign up page&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Sign In button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the web browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;FirstTestScriptUsingSeleniumGrid.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class FirstTestScriptUsingSeleniumGrid {

   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeTest
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "95.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "FirstTestScript");
       capabilities.setCapability("name", "FirstTestScriptSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }

  @Test
   public void firstTestCase() {
       try {
           System.out.println("Logging into Lambda Test Sign Up Page");
           driver.get("https://accounts.lambdatest.com/register");
           WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']"));
           pageHeader.click();
           System.out.println("Clicked on the Sign In Button.");
       } catch (Exception e) {

       }

   }

   @AfterTest
   public void closeBrowser() {
       driver.close();
       System.out.println("The driver has been closed.");

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gist.github.com/RDayal11/54c4be7634c9c29cf69a7639d7e586d1" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will need the below pom.xml for importing the necessary dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pom.xml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

   &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
   &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
   &amp;lt;dependencies&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
   &amp;lt;/dependencies&amp;gt;

   &amp;lt;properties&amp;gt;
       &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
       &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
   &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the below testng.xml file will be needed for running the test case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;testng.xml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="FirstTestScriptUsingSeleniumWebDriverSuite"&amp;gt;

   &amp;lt;test name="FirstTestScriptUsingSeleniumWebDriver" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LambdaTest.FirstTestScriptUsingSeleniumGrid" &amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gist.github.com/RDayal11/54c4be7634c9c29cf69a7639d7e586d1" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global Variables&lt;/strong&gt;: As tests have to be run on LambdaTest cloud Selenium Grid, we would be using the below-shown variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. However, the gridURL will remain the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2148%2F1%2AUYyv75okm1CipizLxFJb4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2148%2F1%2AUYyv75okm1CipizLxFJb4w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@BeforeTest(Setup Method)&lt;/strong&gt;: In Selenium, the RemoteWebDriver class implements the WebDriver interface to execute test scripts through the &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium RemoteWebDriver&lt;/a&gt; server on a remote machine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The @BeforeTest &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;annotation in TestNG&lt;/a&gt; is used to execute a set of statements before running a test suite. This method can be used for initializing the resources required for your test case.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The below-imported class will help you in using the RemoteWebDriver class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2052%2F1%2AnqLcmreIa1EQmT7stkp7ZQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2052%2F1%2AnqLcmreIa1EQmT7stkp7ZQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AWIkhHxk7APaP0Pkas3g4BA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AWIkhHxk7APaP0Pkas3g4BA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@ Test(firstTestCase)&lt;/strong&gt;: In the test case, I opened the &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest sign up page&lt;/a&gt; in the Chrome browser using the driver.get() statement. The &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;findElement method in Selenium&lt;/a&gt; is used for locating the SignIn WebElement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, I have used &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt; for locating the ‘Sign In’ button. To investigate the XPath of any element, you can simply right-click on it and click on Inspect. You will be able to spot the locator in the Elements tab. The &lt;a href="https://www.lambdatest.com/blog/selenium-click-button-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;click method in Selenium&lt;/a&gt; is used for clicking on the Sign In button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A4Iup8MUk7wzaXmAttqySlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A4Iup8MUk7wzaXmAttqySlw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@ AfterTest&lt;/strong&gt;: In the AfterTest method, close the browser using the driver.close() method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2272%2F1%2AwG14UyHdecDrjsqIXKMQtQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2272%2F1%2AwG14UyHdecDrjsqIXKMQtQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution
&lt;/h2&gt;

&lt;p&gt;You will see the below output once you run the testng.xml file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A9D7DzJmhW-PBVQRxPvSeJw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A9D7DzJmhW-PBVQRxPvSeJw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, Log on to &lt;a href="https://automation.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt; to check the status of the test execution on LambdaTest.&lt;/p&gt;

&lt;p&gt;You can also access the report on &lt;a href="https://accounts.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The dashboard shows all the details and metrics related to your tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD-mwRfy-PJpjcBqAubAXGg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD-mwRfy-PJpjcBqAubAXGg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Test Summary gives you a high-level overview of your test performance. It shows how many of your previous tests passed and failed and how effective each team member was in running their tests. Don’t forget to check out Test Overview for interactive visualization of how your tests are performing over time.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/text-uppercase?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Uppercase Text&lt;/strong&gt;&lt;/a&gt; — Online tool for uppercasing all text. Generate any text in uppercase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this automation testing tutorial, we got to know what is automation testing, the differences between manual and automation testing, the need for automation testing, and a few approaches to do the same. We also saw which test cases should be automated and implemented our &lt;a href="https://www.lambdatest.com/blog/how-to-write-test-scripts-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;first automation test script with Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Investment in automation testing is essential to maintain the efficiency and effectiveness of the software development process. It is important to estimate the return on investment &lt;a href="https://www.lambdatest.com/blog/how-do-you-calculate-your-roi-on-test-automation-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr20_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;(ROI) of automation testing&lt;/a&gt;, especially when the company has a tight budget and cannot afford all the requested projects.&lt;/p&gt;

&lt;p&gt;I hope this article helps you in taking the first step towards your automation testing journey and, as a result, helps in achieving a better quality of your software.&lt;/p&gt;

&lt;p&gt;Happy Testing 🙂&lt;/p&gt;

</description>
      <category>testing</category>
      <category>programming</category>
      <category>cloud</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How To Use TestNG Reporter Log In Selenium</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Tue, 19 Apr 2022 07:10:45 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-use-testng-reporter-log-in-selenium-4292</link>
      <guid>https://forem.com/testmuai/how-to-use-testng-reporter-log-in-selenium-4292</guid>
      <description>&lt;p&gt;TestNG is an open-source &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework, where ‘NG’ stands for Next Generation. TestNG has given testers the ability to group or prioritize the test cases, generate HTML reports, log messages, run tests in parallel, and much more. These diverse sets of features are a huge boon when it comes to &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHAC4jrQZTPIJbv6S5KXlyA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHAC4jrQZTPIJbv6S5KXlyA.gif" alt="[https://giphy.com/gifs/kare11-kare-11-news-kent-erdahl-39hwT1SaGT4Bo66t25](https://giphy.com/gifs/kare11-kare-11-news-kent-erdahl-39hwT1SaGT4Bo66t25)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our previous blogs of this &lt;a href="https://www.lambdatest.com/learning-hub/testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium TestNG tutorial&lt;/a&gt; series, we have learned to use the TestNG results plugin, generate the TestNG reports in Jenkins, install the TestNG reports plugin in Jenkins, and more. But why do we need reporting structure in the first place?&lt;/p&gt;

&lt;p&gt;Reports can be insightful as they give us all the accessible information in one place, and with automated report generation structures, they even improve the efficiency and overall analysis. However, sometimes TestNG reports might not convey to us the exact root of failure due to insufficient logging. As a result, we might need to run the whole class to ascertain the problem.&lt;/p&gt;

&lt;p&gt;To overcome this problem, TestNG provides us an inbuilt class called the Reporter Class. In this &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; TestNG tutorial, we will find out how to use the TestNG Reporter Log. By the end of this blog, you would be able to store log super-useful information in the reports.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/random-string-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Random String Generator&lt;/strong&gt;&lt;/a&gt; — The most simple online utility that generates random strings. Free, quick and powerful Random String Generator that allows you to flexibly create random strings ranging from minimum 8 to maximum 25 character length.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Reporter Class in TestNG?
&lt;/h2&gt;

&lt;p&gt;Reporter Class is an inbuilt class in TestNG which is available under the org.testng package. This class provides test methods to log messages that will be included in the HTML reports generated by TestNG. Reporter Class is one of the simplest ways of generating log information.&lt;/p&gt;

&lt;p&gt;It helps in storing logs in the reports that can be either user-generated or system-generated reports. This can be hugely beneficial when we later look at the reports as it helps derive detailed information from the logs. This avoids the need to rerun the entire test case.&lt;/p&gt;

&lt;p&gt;For example, if you have a test case with many steps, Reporter Class can prove to be extremely helpful since you can specify different logs at each step and later use them when debugging the failures.&lt;/p&gt;

&lt;p&gt;Let’s see how we can use the TestNG Reporter Log in Selenium-based test automation framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reporter Class Syntax
&lt;/h2&gt;

&lt;p&gt;Reporter Class of TestNG provides us with four different methods to log information. Isn’t that interesting? Here are those methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reporter.log(String s);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reporter.log(String s, Boolean logToStandardOut);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reporter.log(String s, int level);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reporter.log(String s, int level, Boolean logToStandardOut);&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s go through each one of these TestNG Reporter Log syntaxes in detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Reporter.log(String s);
&lt;/h2&gt;

&lt;p&gt;This method logs the string passed into your HTML Report.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;S — The message to be logged&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reporter.log("Logging into Selenium Playground");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Reporter.log(String s, Boolean logToStandardOut);
&lt;/h2&gt;

&lt;p&gt;This method logs the string passed into your HTML Report. Additionally, it also prints the same message on your console if logToStandardOut is set to TRUE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;S — The message to be logged&lt;br&gt;
logToStandardOut — Print the message on standard output&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reporter.log("Logging into Selenium Playground", true);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Reporter.log(String s, int level);
&lt;/h2&gt;

&lt;p&gt;This method logs the string passed into your HTML Report if the current verbosity equals or is greater than the one passed in the parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;S — The message to be logged&lt;br&gt;
level — The verbosity of the message to be logged&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reporter.log("Logging into Selenium Playground", 2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is Verbosity Level in TestNG?
&lt;/h2&gt;

&lt;p&gt;The Verbose Level in TestNG is used to define the amount of logging performed on the console. The verbosity level ranges from 0 to 10, where 10 is the most detailed logging level whereas 0 means minimal logging.&lt;/p&gt;

&lt;p&gt;You can set the verbosity level in your testng.xml. Below is a sample snippet from the tesng.xml, which indicates how to do the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;suite thread-count="2" name="TestNGReporterTest" parallel="classes" verbose="10"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Reporter.log(String s, int level, Boolean logToStandardOut);
&lt;/h2&gt;

&lt;p&gt;This method logs the string passed into your HTML Report if the current verbosity equals or is greater than the one passed in the parameter. Additionally, it will print the message onto the console if logToStandardOut is set to TRUE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameters:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;S — The message to be logged&lt;br&gt;
level — The verbosity of the message to be logged&lt;br&gt;
logToStandardOut — Whether to print the message on standard output as well&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reporter.log("Logging into Selenium Playground", 2, true);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the demand for automation increases, so does the demand for skilled testers. TestNG helps you become an automation expert. With LambdaTest’s TestNG certification, you can begin your journey to becoming an automated testing expert.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the TestNG certification offered by LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/nCKxl7Q_20I"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/random-sentence-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Random Sentence Generator&lt;/strong&gt;&lt;/a&gt; — Free online tool to generate random sentences effortlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to log messages in reports using TestNG Reporter Class?
&lt;/h2&gt;

&lt;p&gt;Now that we have seen the basics of TestNG Reporter Log in this Selenium TestNG tutorial, let’s deep dive into how we can use the same in our Selenium Automation Framework. We would do the same by demonstrating through a TestNG Reporter Log example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automate the Simple Form Demo Page of Selenium Playground using the Cloud Selenium Grid By LamdaTest.&lt;/p&gt;

&lt;p&gt;LambdaTest provides a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; tool that allows users with an easy way to manage their manual and automated tests across 3000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; and operating systems combinations.&lt;/p&gt;

&lt;p&gt;We will cover the below steps in our test case and use Reporter Class to log all the necessary details.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com/selenium-playground/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on Simple Form Demo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a message in Single Input Field and retrieve the Message&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter a value in the Two Input Fields and retrieve the total of those total values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the actual and expected values.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3578%2F1%2Ak8CRKplNHyarlKfjuOZy3A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3578%2F1%2Ak8CRKplNHyarlKfjuOZy3A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below attached is the test class file, its corresponding testng.xml file, and the pom.xml, which is needed in running the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class ReporterTest {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeTest
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "93.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGReporterLog");
       capabilities.setCapability("name", "TestNGReporterLogSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }


   @Test
   public void learnSingleInputFieldUsingSelenium() {
       try {
           Reporter.log("Logging into Selenium Playground");
           driver.get("https://www.lambdatest.com/selenium-playground/");
           Reporter.log("Logged into Selenium Playground. Now, Clicking On Simple Form Demo", true);

           //Clicks on the simple form demo option in the selenium playground
           WebElement simpleFormDemo = driver.findElement(By.xpath("//a[text()='Simple Form Demo']"));
           simpleFormDemo.click();
           Reporter.log("Clicked successfully on Simple Form Demo option.", 2);

           //Enters the message in the enter message input box
           WebElement messageInputBox = driver.findElement(By.xpath("//input[@id='user-message']"));
           messageInputBox.sendKeys("Running my first testcase using Lambda Test");

           //Clicks on Show Message button
           WebElement showMessageButton = driver.findElement(By.xpath("//button[text()='Show Message']"));
           showMessageButton.click();

           //Retrieves the entered user message
           WebElement userMessage = driver.findElement(By.xpath("//label[text()='Your Message: ']//parent::div//span"));
           String actualUserText = userMessage.getText();
           Reporter.log("Actual User Input Is: " + actualUserText, 2, true);

           Assert.assertTrue(actualUserText.equals("Running my first testcase using Lambda Test"), "Expected and actual texts do not match.");
       } catch (Exception e) {

       }

   }

   @Test
   public void learnMultipleInputFieldUsingSelenium() {
       try {
           Reporter.log("Logging into Selenium Playground");
           driver.get("https://www.lambdatest.com/selenium-playground/");
           Reporter.log("Logged into Selenium Playground. Now, Clicking On Simple Form Demo", true);

           WebElement simpleFormDemo = driver.findElement(By.xpath("//a[text()='Simple Form Demo']"));
           simpleFormDemo.click();
           Reporter.log("Clicked successfully on Simple Form Demo option For Multiple input fields.", 2);

           WebElement firstInputBox = driver.findElement(By.xpath("//input[@id='sum1']"));
           firstInputBox.sendKeys("2");

           WebElement secondInputBox = driver.findElement(By.xpath("//input[@id='sum2']"));
           secondInputBox.sendKeys("2");

           WebElement getTotalButton = driver.findElement(By.xpath("//button[text()='Get Total']"));
           getTotalButton.click();

           WebElement userMessage = driver.findElement(By.xpath("//label[text()='Total a + b = ']//parent::div//span"));
           String actualUserText = userMessage.getText();

           Reporter.log("The total of the two entered user inputs is: " + actualUserText, 2, true);
           Assert.assertTrue(actualUserText.equals("4"), "Expected and actual texts do not match.");
       } catch (Exception e) {

       }

   }

   @AfterTest
   public void closeBrowser() {
       driver.close();
       Reporter.log("The driver has been closed.", false);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub source: &lt;a href="https://gist.github.com/RDayal11/1440f06481e4fda2290da2c30d836b91" rel="noopener noreferrer"&gt;https://gist.github.com/RDayal11/1440f06481e4fda2290da2c30d836b91&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can make use of the below testng.xml to run the above java class. Here, we are running the tests in parallel with 2 threads and a verbosity level of 10. You can right-click on the testng.xml file and choose the Run as TestNG option to run the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite thread-count="2" name="TestNGReporterTest" parallel="classes" verbose="10"&amp;gt;

   &amp;lt;test name="TestNGReporterTest" preserve-order="true"&amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.ReporterTest"&amp;gt;
               &amp;lt;methods&amp;gt;
                   &amp;lt;include name="learnMultipleInputFieldUsingSelenium"/&amp;gt;
                   &amp;lt;include name="learnSingleInputFieldUsingSelenium"/&amp;gt;
               &amp;lt;/methods&amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below pom.xml will be needed for installing all the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

   &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
   &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
   &amp;lt;dependencies&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
   &amp;lt;/dependencies&amp;gt;

   &amp;lt;properties&amp;gt;
       &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
       &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
   &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s try to understand the test case using the TestNG Reporter Log, which we automated.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Imported Dependencies:&lt;/strong&gt; Here, we have imported all the necessary classes, including the Reporter Class needed for using Reporter.log methods.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AumcnMwx2I9buhndfyBIlsA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AumcnMwx2I9buhndfyBIlsA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: As we have used an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt; like LamdaTest to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;, we are using the below-shown variables.&lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LamdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the gridURL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ew2gm92apdzvnuppt05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ew2gm92apdzvnuppt05.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. @ BeforeTest(Setup Method):&lt;/strong&gt; Here, we have made use of the LamdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our Selenium Remote Web Driver. Do refer to our detailed blog that deep dives into the important &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG annotations&lt;/a&gt; that are used for web automation testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. @ Test(learnSingleInputFieldUsingSelenium)&lt;/strong&gt;: Here, the first Reporter.log statement would print our log only on the emailable report since we haven’t used the logToStandardOut flag. However, the following would print the log both on console output and the emailable report since the logToStandardOut is set to True. Finally, the driver.get statement would open the &lt;a href="https://www.lambdatest.com/automation-demos?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; website in the Chrome browser launched in the setup method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2648%2F1%2Awada9CBcb2P6ZBueaHpIOg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2648%2F1%2Awada9CBcb2P6ZBueaHpIOg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once logged into Selenium Playground, the following steps get the SimpleFormDemo web element and click on the same. The Reporter.log statement used here will log the statement in the emailable report as the current verbosity level, which is 10, set through testng.xml, is greater than the value 2 sent here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2218%2F1%2AbPq2EFYxiqiXaNwYBj8PRQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2218%2F1%2AbPq2EFYxiqiXaNwYBj8PRQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we have made use of XPath in our test case for all the web elements. You can get the XPath of any element by simply doing a right-click on the Element→ Inspect Option. You can also refer to the complete guide on &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt; for understanding how you can make the most out of XPath for accessing WebElements in the DOM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2644%2F1%2A7-m7x-nklRptugAwWa10bA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2644%2F1%2A7-m7x-nklRptugAwWa10bA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we are on the Simple Form Demo page, the following steps get the Message Input Box web element and enter the message “Running my first test case using Lambda Test”. Next, we click on the “Show Message” button and retrieve the message displayed, followed by an assert which validates if the entered message and displayed message are equal or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2286%2F1%2Ad2plhxcUmsPJ0hRVBo_i2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2286%2F1%2Ad2plhxcUmsPJ0hRVBo_i2w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Reporter.log statement here will log the report’s message and print the same on the console output. Thus, the final console output will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2246%2F1%2AA2mand5KVXGfNvNmgLhmxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2246%2F1%2AA2mand5KVXGfNvNmgLhmxQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is because the emailable report, as mentioned, contains all the messages we logged.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZkkXuK-fwn8qj_S6ZjqeSg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZkkXuK-fwn8qj_S6ZjqeSg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how our actual output on the playground looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2342%2F1%2A5ANLWyXJ3XlcgNJo0YxZEw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2342%2F1%2A5ANLWyXJ3XlcgNJo0YxZEw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. @ Test(learnMultipleInputFieldUsingSelenium):&lt;/strong&gt; Here, the steps to click on the Simple Form Demo Option remain the same as our first test case. However, in this test case, instead of using the single input field, we first enter “2” in the first input box and then repeat the same for the second input box. Later, we click on the “Get Total” button and validate the values we entered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2822%2F1%2ATcptZPu88JEqsT8CS1gxjw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2822%2F1%2ATcptZPu88JEqsT8CS1gxjw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final console output looks something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACpYY8YOKZbeerxhuogJm3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACpYY8YOKZbeerxhuogJm3g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The emailable report will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWzJ1ThFubFKYOf5OM5R0RQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWzJ1ThFubFKYOf5OM5R0RQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The actual output on the playground will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2012%2F1%2AaR7bN8uF3jDtIgyxiZGlzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2012%2F1%2AaR7bN8uF3jDtIgyxiZGlzg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/random-uuid-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr19_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Random UUID Generator&lt;/strong&gt;&lt;/a&gt; — This free online UUID v4 generator (random UUID) creates version-4 universally unique identifiers according to RFC 4122. Version-4 UUIDs are random and dynamically generated.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to log messages in the Report using ITestListener?
&lt;/h2&gt;

&lt;p&gt;In this Selenium TestNG tutorial, we saw how we could use the Reporter.log() method in our test cases and log the desired messages in the Report (as well as the console). However, what if we want to print any log before the test execution starts or after the test execution has ended.&lt;/p&gt;

&lt;p&gt;TestNG provides us with a lot of Listeners (e.g. IAnnotationTransformer, IReporter, etc). These interfaces are used while performing Selenium automation testing mainly to generate logs and customize the TestNG reports. Here we will make use of ITestListener. You can use the below Listener.java, which is implementing the ITestListener.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package util;

import org.testng.*;

public class Listener implements ITestListener {

   // This belongs to ITestListener and will execute before the whole Test starts

   @Override
   public void onStart(ITestContext arg0) {
       Reporter.log("About to begin executing Class " + arg0.getName(), true);
   }

   // This belongs to ITestListener and will execute, once the whole Test is finished

   @Override
   public void onFinish(ITestContext arg0) {
       Reporter.log("About to end executing Class " + arg0.getName(), true);
   }
   // This belongs to ITestListener and will execute before each test method

   @Override
   public void onTestStart(ITestResult arg0) {
       Reporter.log("Testcase " + arg0.getName() + " started successfully", true);
   }

   // This belongs to ITestListener and will execute only in the event of a successful test method
   public void onTestSuccess(ITestResult arg0) {
       Reporter.log("Testcase " + arg0.getName() + " passed successfully", true);
   }

   // This belongs to ITestListener and will execute only in the event of a fail test

   public void onTestFailure(ITestResult arg0) {
       Reporter.log("Testcase " + arg0.getName() + " failed", true);
   }

   // This belongs to ITestListener and will execute only in the event of the skipped test method

   public void onTestSkipped(ITestResult arg0) {
       Reporter.log("Testcase " + arg0.getName() + " got skipped", true);
   }

   @Override
   public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub source: &lt;a href="https://gist.github.com/RDayal11/1440f06481e4fda2290da2c30d836b91" rel="noopener noreferrer"&gt;https://gist.github.com/RDayal11/1440f06481e4fda2290da2c30d836b91&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onStart&lt;/strong&gt;: Here, Reporter.log will log the message before the execution of the whole class starts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OnFinish&lt;/strong&gt;: Here, Reporter.log will log the message once the execution of the whole class has finished.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onTestStart&lt;/strong&gt;: Here, Reporter.log will log the message before the execution of the individual test methods starts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onTestSuccess&lt;/strong&gt;: Here, Reporter.log will log the message only if the execution of the test method has been completed with Success State.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onTestFailure&lt;/strong&gt;: Here, Reporter.log will log the message only if the execution of the test method has been completed with Failed State.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;onTestSkipped&lt;/strong&gt;: Here, Reporter.log will log the message only if the execution of the test method has been skipped.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the case of ITestListener, you can choose to implement only those methods which you intend to.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use this Listener Class in the test class?
&lt;/h2&gt;

&lt;p&gt;To implement the above-described methods, you can simply add an annotation in your test class just above your class name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Listeners(PackageName.ClassName.class)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0G02T_32MzTYoYSqxV94Dg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0G02T_32MzTYoYSqxV94Dg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ad-oqGPUqN11bH1Arp845Qg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ad-oqGPUqN11bH1Arp845Qg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to view the logged messages in EmailableReport in TestNG?
&lt;/h2&gt;

&lt;p&gt;Once you have run your test case, refresh your project and go to the test-output folder. You will find an emailable-report.html inside it, which can be viewed using any browser. In addition, the emailable-report.html will have all your messages logged.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ay3yNBtUQbQsqgQQ8Eq7zCQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ay3yNBtUQbQsqgQQ8Eq7zCQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you open the report, it will look as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2164%2F1%2AEzA6R8-XjrCiYzsjRKps8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2164%2F1%2AEzA6R8-XjrCiYzsjRKps8Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this Selenium TestNG tutorial, we learned what is Reporter Class in TestNG and how we can use the different parameters it offers. We also ran our first test script using the Reporter class on Cloud Selenium Grid offered by LamdaTest and logged a few messages. We also learned how we could make use of the Reporter Class in ITestListeners. We got the logs printed on the console and finally saw them getting logged in our EmailableReport. I hope you enjoyed reading this article and learned some more about the TestNG Reporter Log.&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How To Set Test Case Priority In TestNG With Selenium</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Mon, 18 Apr 2022 11:01:47 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-set-test-case-priority-in-testng-with-selenium-15o3</link>
      <guid>https://forem.com/testmuai/how-to-set-test-case-priority-in-testng-with-selenium-15o3</guid>
      <description>&lt;p&gt;TestNG is an open-source and powerful &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework with a wide range of features, including annotations, data providers, group testing, prioritization, and much more.&lt;/p&gt;

&lt;p&gt;Prioritization in TestNG is an easy way to set test case priority and run your test case in the exact order you want. This feature is particularly useful when defining a sequence for the test case execution when you have multiple test cases or assign precedence to a few methods over others. For example, if you want your login scenario to run first, followed by adding an item to your cart, you don’t need to worry as TestNG has got you all covered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AhaNpmKo6wzLnZtAkF1Xf9A.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AhaNpmKo6wzLnZtAkF1Xf9A.gif" alt="[https://giphy.com/gifs/theoffice-gphyoffice726-DpSoj00vkPpswwZU9o](https://giphy.com/gifs/theoffice-gphyoffice726-DpSoj00vkPpswwZU9o)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our previous blogs of this &lt;a href="https://www.lambdatest.com/learning-hub/testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium TestNG tutorial&lt;/a&gt; series, we have learned &lt;a href="https://www.lambdatest.com/blog/how-to-install-testng-in-eclipse-step-by-step-guide/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to install TestNG&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to use annotations in TestNG&lt;/a&gt;, and much more. In this blog, we will cover how to set test case priority in TestNG while performing &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; automation testing.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/md2-hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;MD2 Hash Calculator&lt;/strong&gt;&lt;/a&gt; — Free online tool that computes MD2 hash of text and strings.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is test Priority in TestNG?
&lt;/h2&gt;

&lt;p&gt;In TestNG, Priority is an attribute that helps the users define the order in which they want the test cases to be executed.&lt;/p&gt;

&lt;p&gt;When you have multiple test cases and want them to run in a particular order, you can use the Priority attribute to set test priority in TestNG. The test cases get executed following an ascending order in the priority list, and hence, test cases with lower priority will always get executed first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax for using test Priority in TestNG
&lt;/h2&gt;

&lt;p&gt;To set test case priority in TestNG, we need to add annotation as &lt;strong&gt;@ Test (priority=X)&lt;/strong&gt;. In the below-shown example, we have given a priority of 1 to the test case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test(priority = 1)
public void myTestCaseWithPriority() {
   try {
       System.out.println("I am in my first testcase with priority=1");
   } catch (Exception e) {
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is default Priority in TestNG?
&lt;/h2&gt;

&lt;p&gt;The default test priority in TestNG is 0. So, when you don’t set test priority in TestNG explicitly to the test cases, TestNG assigns them a priority of 0.&lt;/p&gt;

&lt;p&gt;For example, the below-shown test case doesn’t have any priority set, and hence, it assumes a priority of 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
public void myTestCaseWithDefaultPriority() {
   try {
       System.out.println("I am in my first testcase with default priority");
   } catch (Exception e) {

   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With TestNG certification, you can challenge your skills in performing automated testing with TestNG and take your career to the next level.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the TestNG certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dzXX2hJhuCY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set negative Priority in TestNG?
&lt;/h2&gt;

&lt;p&gt;If you wonder whether we can assign a negative priority value to any test case, the answer is Yes!! We can assign a negative priority to the test methods when we want them to take precedence over the default ones.&lt;/p&gt;

&lt;p&gt;The below-shown example has two test methods, one with a default priority 0 and the other with negative priority, i.e., -1. Hence, the test method with negative priority will always be executed first, followed by the test method with default priority.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
public void myTestCaseWithDefaultPriority() {
   try {
       System.out.println("I am in my first testcase with default priority");
   } catch (Exception e) {

   }

}

@Test(priority = -1)
public void myTestCaseWithNegativePriority() {
   try {
       System.out.println("I am in my first testcase with negative priority");
   } catch (Exception e) {

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Console Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3kq9qLaF0K0XmlFLwVFogg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3kq9qLaF0K0XmlFLwVFogg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to test with the same Priority in TestNG?
&lt;/h2&gt;

&lt;p&gt;You must wonder what happens if you have a test case with all or some of the methods having the same priority. In such cases, TestNG follows an alphabetical order while executing them.&lt;/p&gt;

&lt;p&gt;The below example has two test methods (a and b), and both have the same default priority that is 0. Therefore, the order of execution will be method a followed by b.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Test
public void a() {
   try {
       System.out.println("A");
   } catch (Exception e) {

   }

}

@Test
public void b() {
   try {
       System.out.println("B");
   } catch (Exception e) {

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Console Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArkDclHNzOTCuxFaH3EwxJQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArkDclHNzOTCuxFaH3EwxJQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set test case Priority in TestNG using Selenium?
&lt;/h2&gt;

&lt;p&gt;In this blog on how to set test case priority in TestNG, we have learned the fundamentals of priority in TestNG. In this section of the Selenium TestNG tutorial, we will see how test priority in TestNG works or how to set test case priority in TestNG.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Scenario:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will automate the main page of &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LamdaTest and print the headers of all the sections sequentially.&lt;/p&gt;

&lt;p&gt;LambdaTest is an automated &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform. With over 2000 &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser&lt;/a&gt; and OS combos, it lets you manage your manual and automated tests in one place with ease.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3580%2F1%2AHozQezsMs4kz0j2gNGuxjQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3580%2F1%2AHozQezsMs4kz0j2gNGuxjQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will implement the problem scenario in four different ways, as listed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When all the methods are without priority&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When all the methods are with priority&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When all the methods are with the same priority&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When there are both methods with and without priority&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are getting started with running TestNG scripts using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;, you can refer to our blog on &lt;a href="https://www.lambdatest.com/blog/create-testng-project-in-eclipse-run-selenium-test-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Create TestNG Project In Eclipse &amp;amp; Run Selenium Test Script&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/lines-count?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;Lines Count&lt;/strong&gt;&lt;/a&gt;— Free online tool to calculate the number of lines in any given text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing test case Priority when methods are without Priority in TestNG
&lt;/h2&gt;

&lt;p&gt;In this section of the Selenium TestNG tutorial, we will see how to set test case priority in TestNG when all the methods are without any priority using a sample Selenium automation code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;

class SeleniumPlaygroundTestsWithoutPriority {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "94.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGWithoutPriorityTests");
       capabilities.setCapability("name", "TestNGWithoutPriorityTestsSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
       Reporter.log("Logging into Selenium Playground", true);
       driver.get("http://labs.lambdatest.com/selenium-playground/");
   }

   @Test
   public void getFirstOptionName() {
       try {
           WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
           Reporter.log("The First Option Is: " + option1.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getSecondOptionName() {
       try {
           WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
           Reporter.log("The Second Option Is: " + option2.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getThirdOptionName() {
       try {
           WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
           Reporter.log("The Third Option Is: " + option3.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getFourthOptionName() {
       try {
           WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
           Reporter.log("The Fourth Option Is: " + option4.getText(), true);
       } catch (Exception e) {

       }

   }


   @Test
   public void getFifthOptionName() {
       try {
           WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
           Reporter.log("The Fifth Option Is: " + option5.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getSixthOptionName() {
       try {
           WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
           Reporter.log("The Sixth Option Is: " + option6.getText(), true);
       } catch (Exception e) {

       }

   }

   @AfterClass
   public void closeBrowser() {
       driver.close();
       Reporter.log("Closing the browser", true);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the below testng.xml file for running the above test class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="TestNGPriorityTest"&amp;gt;

   &amp;lt;test name="TestNGPriorityTest" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.SeleniumPlaygroundTestsWithoutPriority"&amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The below pom.xml can be used for installing all the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

   &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
   &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
   &amp;lt;dependencies&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
   &amp;lt;/dependencies&amp;gt;

   &amp;lt;properties&amp;gt;
       &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
       &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
   &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Imported Dependencies&lt;/strong&gt;: Here, we have imported all the necessary classes, including the Desired Capabilities, Reporter Class, etc., for using the corresponding methods. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reporter Class is an inbuilt class in TestNG and is used for logging messages in the HTML Reports and Standard Output.&lt;/p&gt;

&lt;p&gt;You can refer to &lt;a href="https://www.lambdatest.com/blog/how-to-use-testng-reporter-log-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;How to Use TestNG Reporter Class In Selenium&lt;/a&gt; that deep dives into the details of Reporter Class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ae-LbgystwwW61ZjqvA8uew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ae-LbgystwwW61ZjqvA8uew.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: Here, we have used an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt; like LamdaTest to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LamdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ag_-WMlb9TrfUKHwlhjvSKw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ag_-WMlb9TrfUKHwlhjvSKw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. @ BeforeClass(Setup Method)&lt;/strong&gt;: Here, we have used the LamdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Remote Web Driver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Do refer to our detailed blog that deep dives into the important &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG annotations&lt;/a&gt; that are used for web automation testing.&lt;/p&gt;

&lt;p&gt;Along with setting the desired capabilities, we are logging into the Selenium Playground in the Before Class Method to use the platform for all the following test methods by logging in once.&lt;/p&gt;

&lt;p&gt;We are also logging the text message “Logging into Selenium Playground” in our HTML Report as well as standard output by making use of the Reporter Class Method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2882%2F1%2AtaG2bXkqKCT6PeUkKm58ug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2882%2F1%2AtaG2bXkqKCT6PeUkKm58ug.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. @ Test(getFirstOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the first section of the Selenium Playground highlighted below. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be Input Forms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3378%2F1%2AeXsotdJWcfc7lc6kOtHadQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3378%2F1%2AeXsotdJWcfc7lc6kOtHadQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since there is no priority explicitly set, the test method will assume the default priority of 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2544%2F1%2AqXkPDRDdBggIif99Pe1qFg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2544%2F1%2AqXkPDRDdBggIif99Pe1qFg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we have made use of XPath in our test case for all the web elements. You can get the XPath of any element by simply doing a right-click on the Element→ Inspect Option. You can also refer to the complete guide on &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt; for understanding how you can make the most out of XPath for accessing WebElements in the DOM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AicmFanWV0xVKNsJ50KE2nQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AicmFanWV0xVKNsJ50KE2nQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. @ Test(getSecondOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the second section of the Selenium Playground. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be Progress Bars &amp;amp; Sliders. The test method here again assumes the default priority of 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. @ Test(getThirdOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the third section of the Selenium Playground. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be Alerts &amp;amp; Modals. The test method assumes the default priority of 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. @ Test(getFourthOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the fourth section of the Selenium Playground. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be Date Pickers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. @ Test(getFifthOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the fifth section of the Selenium Playground. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be Table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. @ Test(getSixthOptionName)&lt;/strong&gt;: In this method, we are getting the Web Element of the header of the sixth section of the Selenium Playground. Then, we are printing the text of the same Web Element, using Reporter Class on the console and HTML Report. Here, the text of the web element printed on the console will be List Box.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. @ AfterClass(closeBrowser)&lt;/strong&gt;: In this method, we are simply closing the browser launched before class once all the test methods are executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since no priority was explicitly mentioned for all the above-shown test methods, TestNG will assign them a default priority of 0. Now, as explained in Tests With Same Priority In TestNG, to tie break between all these methods having the same priority, TestNG will follow alphabetical order while executing them. As a result, console output will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2598%2F1%2AJ0et1KjLmdWEl1-TQL1-Xw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2598%2F1%2AJ0et1KjLmdWEl1-TQL1-Xw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can further check the execution results of your test published at &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While your test is running, you can also see the live video streaming of your tests and various other details such as logs or exceptions raised.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3434%2F1%2A-Iq_6E2jPn5A5J4KuZVD8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3434%2F1%2A-Iq_6E2jPn5A5J4KuZVD8w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/md5-hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;&lt;strong&gt;MD5 Hash Calculator&lt;/strong&gt;&lt;/a&gt; — Free online tool to generate MD5 Hash values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing test case Priority when methods are with Priority in TestNG
&lt;/h2&gt;

&lt;p&gt;In the previous section of this blog on how to set test case priority in TestNG, you saw the test methods getting executed alphabetically since they had a default priority assigned. Now, let’s see how the same test case would behave when we explicitly assign priority to the test methods while performing Selenium automation testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

class SeleniumPlaygroundTestsWithPriority {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "93.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGWithPriorityTests");
       capabilities.setCapability("name", "TestNGWithPriorityTestsSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
       Reporter.log("Logging into Selenium Playground", true);
       driver.get("http://labs.lambdatest.com/selenium-playground/");
   }

   @Test(priority = 1)
   public void getFirstOptionName() {
       try {
           WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
           Reporter.log("The First Option Is: " + option1.getText(), true);
           System.out.println("I am in my first testcase with priority=1");
       } catch (Exception e) {

       }

   }

   @Test(priority = 2)
   public void getSecondOptionName() {
       try {
           WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
           Reporter.log("The Second Option Is: " + option2.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 3)
   public void getThirdOptionName() {
       try {
           WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
           Reporter.log("The Third Option Is: " + option3.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 4)
   public void getFourthOptionName() {
       try {
           WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
           Reporter.log("The Fourth Option Is: " + option4.getText(), true);
       } catch (Exception e) {

       }

   }


   @Test(priority = 5)
   public void getFifthOptionName() {
       try {
           WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
           Reporter.log("The Fifth Option Is: " + option5.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 6)
   public void getSixthOptionName() {
       try {
           WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
           Reporter.log("The Sixth Option Is: " + option6.getText(), true);
       } catch (Exception e) {

       }

   }

   @AfterClass
   public void closeBrowser() {
       driver.close();
       Reporter.log("Closing the browser", true);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The below testng.xml file can be used for running the above Java class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="TestNGPriorityTest"&amp;gt;

   &amp;lt;test name="TestNGPriorityTest" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.SeleniumPlaygroundTestsWithPriority"&amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this test case, the scenario remains the same as what we saw in our first example, except that all the methods have been assigned a priority here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since all the test methods had their respective priorities assigned, TestNG will execute them in ascending order of their priorities. Hence, the method getFirstOptionName with priority=1 will be executed first, followed by getSecondOptionName with priority=2, and so on. As a result, console output looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4phqQ7fXipbbcYFNfJV-Pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4phqQ7fXipbbcYFNfJV-Pg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can further check the LamdaTest Automation Dashboard to check your test results and logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3420%2F1%2Ak1ZRQDpFKW9I6Q4jFGHt2Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3420%2F1%2Ak1ZRQDpFKW9I6Q4jFGHt2Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing test case Priority when methods are with the same Priority in TestNG
&lt;/h2&gt;

&lt;p&gt;In the previous section of this blog on how to set test case priority in TestNG, we saw how easily TestNG picked up our test methods based on their priority in ascending order, but what if the methods had the same priority assigned. So let’s see how our test result would look if the same test methods run with an equal priority assigned.&lt;/p&gt;

&lt;p&gt;In this method, we will also assign a negative priority to a few of our test methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

class SeleniumPlaygroundTestsWithSamePriority {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "93.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGWithSamePriorityTests");
       capabilities.setCapability("name", "TestNGWithSamePriorityTestsSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
       Reporter.log("Logging into Selenium Playground", true);
       driver.get("http://labs.lambdatest.com/selenium-playground/");
   }

   @Test(priority = 1)
   public void getFirstOptionName() {
       try {
           WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
           Reporter.log("The First Option Is: " + option1.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 1)
   public void getSecondOptionName() {
       try {
           WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
           Reporter.log("The Second Option Is: " + option2.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 2)
   public void getThirdOptionName() {
       try {
           WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
           Reporter.log("The Third Option Is: " + option3.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = -1)
   public void getFourthOptionName() {
       try {
           WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
           Reporter.log("The Fourth Option Is: " + option4.getText(), true);
       } catch (Exception e) {

       }

   }


   @Test(priority = -2)
   public void getFifthOptionName() {
       try {
           WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
           Reporter.log("The Fifth Option Is: " + option5.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = -3)
   public void getSixthOptionName() {
       try {
           WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
           Reporter.log("The Sixth Option Is: " + option6.getText(), true);
       } catch (Exception e) {

       }

   }

   @AfterClass
   public void closeBrowser() {
       driver.close();
       Reporter.log("Closing the browser", true);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the below testng.xml file for running the above Java class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="TestNGPriorityTest"&amp;gt;

   &amp;lt;test name="TestNGPriorityTest" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.SeleniumPlaygroundTestsWithSamePriority"&amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this test case, the scenario remains the same as what we saw in our first and second examples, except that all the methods have been assigned a priority here, two of them having the same priority and few being assigned a negative priority.&lt;/p&gt;

&lt;p&gt;Let’s decode how our results would look like. Here, the test method getSixthOptionName is assigned the lowest priority of -3, and hence, it will be picked up first, followed by getFifthOptionName with priority = -2, and then getFourthOptionName with priority = -1.&lt;/p&gt;

&lt;p&gt;After these, there are two test methods getFirstOptionName and getSecondOptionName running with the same priority = 1. Hence, out of these two, getFirstOptionName will be executed first, since it comes first alphabetically followed by getSecondOptionName. The last method to be executed will be getThirdOptionName running with priority = 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As expected, the console output will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFNsLGdZH3aS6Y7rArMIaiA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFNsLGdZH3aS6Y7rArMIaiA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can further check the LamdaTest Automation Dashboard to check your test results and logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3502%2F1%2AU4uBX3rpp-FqSJo2tCskZw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3502%2F1%2AU4uBX3rpp-FqSJo2tCskZw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing test case Priority with both Prioritized and Non-Prioritized methods in TestNG
&lt;/h2&gt;

&lt;p&gt;In the previous section of this blog on how to set test case priority in TestNG, we had either all the test methods without any priority set or all running with priority. But can we have a combination of both prioritized and non-prioritized methods in TestNG? The answer is YES.&lt;/p&gt;

&lt;p&gt;Let’s explore a sample test case and understand how TestNG would execute our test methods in such scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

class SeleniumPlaygroundTestsWithAndWithoutPriority {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "93.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGWithAndWithoutPriorityTests");
       capabilities.setCapability("name", "TestNGWithAndWithoutPriorityTestsSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
       Reporter.log("Logging into Selenium Playground", true);
       driver.get("http://labs.lambdatest.com/selenium-playground/");
   }

   @Test
   public void getFirstOptionName() {
       try {
           WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
           Reporter.log("The First Option Is: " + option1.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getSecondOptionName() {
       try {
           WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
           Reporter.log("The Second Option Is: " + option2.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 1)
   public void getThirdOptionName() {
       try {
           WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
           Reporter.log("The Third Option Is: " + option3.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 1)
   public void getFourthOptionName() {
       try {
           WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
           Reporter.log("The Fourth Option Is: " + option4.getText(), true);
       } catch (Exception e) {

       }

   }


   @Test(priority = 0)
   public void getFifthOptionName() {
       try {
           WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
           Reporter.log("The Fifth Option Is: " + option5.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test(priority = 2)
   public void getSixthOptionName() {
       try {
           WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
           Reporter.log("The Sixth Option Is: " + option6.getText(), true);
       } catch (Exception e) {

       }

   }

   @AfterClass
   public void closeBrowser() {
       driver.close();
       Reporter.log("Closing the browser", true);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the below testng.xml for running the Java class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="TestNGPriorityTest"&amp;gt;

   &amp;lt;test name="TestNGPriorityTest" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.SeleniumPlaygroundTestsWithAndWithoutPriority"&amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this test case, the scenario remains the same as what we saw until now, except that some methods have been assigned a priority here while some are running with default priority.&lt;/p&gt;

&lt;p&gt;Let’s see how our results would look like, Here, the test methods getFifthOptionName has been assigned a priority =0, but it still falls at the same level as methods getFirstOptionName and getSecondOptionName since even though they are not assigned any priority explicitly, they will run with the default priority which is 0. Hence, out of all these three methods, getFifthOptionName will run first, followed by getFirstOptionName and getSecondOptionName, considering their alphabetical order. After these, the test method getFourthOptionName will be executed, followed by getThirdOptionName as both of them have the same priority set, which is 1. In the end, getSixthOptionName will be executed since it is running with a priority of 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As expected, the console output will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4phqQ7fXipbbcYFNfJV-Pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4phqQ7fXipbbcYFNfJV-Pg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can further check the LamdaTest Automation Dashboard to check your test results and logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3420%2F1%2Ak1ZRQDpFKW9I6Q4jFGHt2Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3420%2F1%2Ak1ZRQDpFKW9I6Q4jFGHt2Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TestNG issue when running tests with same Priority and in Parallel
&lt;/h2&gt;

&lt;p&gt;We saw how to set case priority in TestNG and how the TestNG priority worked in different scenarios when they had the same or different priority set or even when they had no priority set. However, the scenarios where the same priority assigned methods could behave a little differently if you would run them in parallel.&lt;/p&gt;

&lt;p&gt;You can refer to &lt;a href="https://www.lambdatest.com/blog/create-testng-xml-file-execute-parallel-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Create TestNG XML File &amp;amp; Execute Parallel Testing&lt;/a&gt; that deep dives into the details of parallel testing in TestNG using TestNG XML file.&lt;/p&gt;

&lt;p&gt;For example, If we use our same test case where all the methods had no priority explicitly defined, which means they run with a default priority, i.e., 0 but, instead of running the test methods sequentially, let’s run them in parallel and see how the result would look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LamdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

class SeleniumPlaygroundTestsWithoutPriority {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "94.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "TestNGWithoutPriorityTests");
       capabilities.setCapability("name", "TestNGWithoutPriorityTestsSample");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
       Reporter.log("Logging into Selenium Playground", true);
       driver.get("http://labs.lambdatest.com/selenium-playground/");
   }

   @Test
   public void getFirstOptionName() {
       try {
           WebElement option1 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[1]"));
           Reporter.log("The First Option Is: " + option1.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getSecondOptionName() {
       try {
           WebElement option2 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[2]"));
           Reporter.log("The Second Option Is: " + option2.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getThirdOptionName() {
       try {
           WebElement option3 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[3]"));
           Reporter.log("The Third Option Is: " + option3.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getFourthOptionName() {
       try {
           WebElement option4 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[4]"));
           Reporter.log("The Fourth Option Is: " + option4.getText(), true);
       } catch (Exception e) {

       }

   }


   @Test
   public void getFifthOptionName() {
       try {
           WebElement option5 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[5]"));
           Reporter.log("The Fifth Option Is: " + option5.getText(), true);
       } catch (Exception e) {

       }

   }

   @Test
   public void getSixthOptionName() {
       try {
           WebElement option6 = driver.findElement(By.xpath("(//div[@class='contentlearn']//h2)[6]"));
           Reporter.log("The Sixth Option Is: " + option6.getText(), true);
       } catch (Exception e) {

       }

   }

   @AfterClass
   public void closeBrowser() {
       driver.close();
       Reporter.log("Closing the browser", true);

   }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s use the below testng.xml and run the same class in parallel with a thread count of 6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="TestNGPriorityTest" parallel="methods" thread-count="6" &amp;gt;

   &amp;lt;test name="TestNGPriorityTest"&amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LamdaTest.SeleniumPlaygroundTestsWithoutPriority"&amp;gt;
           /class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Execution Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now ideally, the test methods should have been executed in alphabetical order since they all had a default priority of 0 assigned. So, getFifthOptionName should run first, followed by getFirstOptionName, and so on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcswLKyZpiA0JMm16Srgt5Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcswLKyZpiA0JMm16Srgt5Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Actual Results:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The test methods get executed in a random sequence instead of alphabetical order since we are running them in parallel.&lt;/p&gt;

&lt;p&gt;The console output shows that the methods have been executed in a random sequence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcSbd9nI6aihrCOkyvoXOOw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcSbd9nI6aihrCOkyvoXOOw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; The same works fine if we simply remove the parallel and thread-count attribute from our testng.xml file.&lt;/p&gt;

&lt;p&gt;One thing important to consider here is that you would only face this problem when the methods have the same priority. The execution order remains exactly as expected when those methods run with different priorities assigned and in parallel.&lt;/p&gt;

&lt;p&gt;You can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; by scanning the below QR code and stay up to date with the latest tutorials around Selenium automation testing, cross browser testing, and more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AbrvJVcSEAYSdUX9yYsgKtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AbrvJVcSEAYSdUX9yYsgKtg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog on how to set test case priority in TestNG, we learned about the Priority attribute in TestNG and how we can use it while performing &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr18_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A37CzKsE-9N2w4rIQCTdVWA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A37CzKsE-9N2w4rIQCTdVWA.gif" alt="[https://giphy.com/gifs/jointeamalpha-alpha-nerdist-orbital-redux-KYFirqLIwVNYHOtpHc](https://giphy.com/gifs/jointeamalpha-alpha-nerdist-orbital-redux-KYFirqLIwVNYHOtpHc)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We saw how TestNG handles any negative priority, or when all methods have the same priority and when all methods have different priorities. We also came across the limitation of TestNG, which happens when the methods have the same priority assigned, and they are being run in parallel.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this Selenium TestNG tutorial on how to set test case priority in TestNG and understood about setting test case priority in TestNG.&lt;/p&gt;

&lt;p&gt;Happy Testing !!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>test</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How To Implement Shift Left Testing Approach</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Thu, 14 Apr 2022 08:01:25 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-implement-shift-left-testing-approach-31fg</link>
      <guid>https://forem.com/testmuai/how-to-implement-shift-left-testing-approach-31fg</guid>
      <description>&lt;p&gt;The “shift left” approach is based on the principle that if the software development team can test code as it is being developed, they can discover errors earlier than if they wait until the end of the project. The &lt;a href="https://www.lambdatest.com/shift-left-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;shift left testing&lt;/a&gt; approach encourages developers to write tests earlier in the development cycle, before code is released for testing.&lt;/p&gt;

&lt;p&gt;Shift left testing process is an agile software development practice that emphasizes putting test cases in place early in a project’s life cycle, meaning during initial development phases rather than at the end. It also means that, instead of just covering a small percentage of a project’s expected functionality, a large percentage of the functionality will be covered by automated tests.&lt;/p&gt;

&lt;p&gt;Shift left testing is also instrumental in reducing the number of defects that find their way into the production software. It’s about &lt;a href="https://www.lambdatest.com/blog/starting-automation-testing-from-scratch-here-is-what-you-need-to-know/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;shifting from manual to automated testing&lt;/a&gt; so that by the time you need to do manual testing, there is less work to be done from a quality standpoint. In essence, it aims to catch bugs earlier so that they are easier and cheaper to fix at the early stages of the development lifecycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AOH09hg6dqT09HpmEfkoCqw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AOH09hg6dqT09HpmEfkoCqw.gif" alt="[https://giphy.com/gifs/tainy-spongebob-sponge-on-the-run-krabby-step-ZQcWjQTuaavwlRIT77](https://giphy.com/gifs/tainy-spongebob-sponge-on-the-run-krabby-step-ZQcWjQTuaavwlRIT77)" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, before discussing the shift left testing process in detail, we need to understand a typical Software Development Life Cycle (SDLC) and the fundamentals of Shift Right Testing.&lt;/p&gt;

&lt;p&gt;This article on shift left testing will guide you about the shift left testing approach and how teams can leverage &lt;a href="https://www.lambdatest.com/blog/how-shift-left-testing-can-help-your-product-quality/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;shift left testing to improve the product quality&lt;/a&gt; and more.&lt;/p&gt;

&lt;p&gt;Let’s Get Started!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Software Development Life Cycle (SDLC)?
&lt;/h2&gt;

&lt;p&gt;In order to understand the shift left testing approach, let us first see what is the Software Development Life Cycle and what are the different stages involved in the cycle.&lt;/p&gt;

&lt;p&gt;Software Development Life Cycle (SDLC) is a step-by-step approach to developing any software. It provides us with various models that help us define a methodology to improve the overall quality of the product, along with helping teams improve the software development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the different stages in a traditional SDLC Model (Waterfall Model)?
&lt;/h2&gt;

&lt;p&gt;We have various SDLC Models available today in the market, the Waterfall Model is the most popular one from the lot. It is a sequential process where you identify all the tasks in advance and then execute them in a sequential manner.&lt;/p&gt;

&lt;p&gt;However, the Waterfall model is losing its popularity (at a rapid pace) as software development companies worldwide are adopting Agile methodologies for developing their product. You can deep dive into &lt;a href="https://www.lambdatest.com/blog/agile-vs-waterfall-methodology/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Agile vs Waterfall methodology&lt;/a&gt; comparison to choose the right model for your product.&lt;/p&gt;

&lt;p&gt;The below image shows the various steps involved in a typical Waterfall Model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4j3qra1hcyqhbqxolrk.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4j3qra1hcyqhbqxolrk.jpeg" width="800" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, there are different stages involved in a typical software development life cycle.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Planning &amp;amp; Requirement Analysis&lt;/strong&gt;: This is the most important and fundamental stage in SDLC. This stage involves gathering requirements from the customers, market surveys, and other relevant sources that drive the overall product architecture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Design&lt;/strong&gt;: Once the requirements have been gathered and documented, the next stage involves designing the architecture of the overall product based on the requirements that were gathered in the earlier stage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implementation/Development&lt;/strong&gt;: In this stage, the actual product development is started and the product is built and pushed to the QA team to carry out the testing activities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing: Here comes the role of QA to start testing the product, report issues, and finally certify it so that customers can use the product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deployment&lt;/strong&gt;: This is the stage where the product is finally deployed for the customers to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintenance&lt;/strong&gt;: The maintenance phase includes enhancing the features and solving issues reported by the customers, which eventually helps in making a better quality product.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: JavaScript &lt;a href="https://www.lambdatest.com/web-technologies/typedarrays?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;typed arrays&lt;/strong&gt;&lt;/a&gt; provide a mechanism for accessing raw binary data much more efficiently than can be done with the standard JavaScript getters and setters.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Shift Right Testing?
&lt;/h2&gt;

&lt;p&gt;Shift right testing suggests moving the testing activities later in the Software Development Life Cycle, usually after the software has been deployed in the production environments. Thus, it is also known as “Testing In Production,” and it helps uncover issues that could not be detected within the development or testing environments.&lt;/p&gt;

&lt;p&gt;In simple terms, shift right testing is performed on applications that are already built and released to the end-customer. This testing practice is widely being adopted these days and is closely tied to DevOps activities.&lt;/p&gt;

&lt;p&gt;The goal of shift right testing is to mainly ensure correct performance, stability, and usability of the application in the production environment. The feedback and reviews are thus collected from targeted users to understand the software’s function in real-world conditions. This helps enhance the quality of the software much further.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Shift Left Testing?
&lt;/h2&gt;

&lt;p&gt;You saw how the traditional Waterfall model works where testing comes into the picture very late in the cycle or the shift right testing, where testing is done at the end or right of the cycle. Shift right testing is ideal for improving product quality and performance by solving issues that are witnessed in the production environment.&lt;/p&gt;

&lt;p&gt;However, the shift left testing approach suggests moving the Testing activities “Left” or rather “earlier” in the development cycle. Thus, it involves the testers much earlier in the software development life cycle. It aims to identify bugs and bottlenecks earlier in the development process.&lt;/p&gt;

&lt;p&gt;As a result, it improves the quality of the code and reduces the overall time consumed in the cycle. It helps in ensuring that fewer defects make it to the production environment.&lt;/p&gt;

&lt;p&gt;Compared to shift right testing, where the testing was at the extreme right of the development cycle, the shift left testing approach involves testing at each development phase. Overall, it focuses on &lt;a href="https://www.lambdatest.com/blog/continuous-testing-using-shift-left-testing-approach/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;continuous testing&lt;/a&gt; throughout the development cycle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F648n5awcu7rfjk0dfw2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F648n5awcu7rfjk0dfw2q.png" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance Of Shift Left Testing approach
&lt;/h2&gt;

&lt;p&gt;In the traditional Waterfall model, where the testing is carried out at the end of the cycle, a situation arises where severe defects are caught. It is difficult and costly to fix such critical bugs at the end of the cycle. The cost involved in fixing bugs rises exponentially with its discovery stage.&lt;/p&gt;

&lt;p&gt;As a result, late testing in the cycle leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increased costs owing to bug discovery at a later stage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Longer bug fix times&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error-prone software since the QA gets less time to validate the entire product&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lesser time for automating the tests, which eventually leads to regression defects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Poor end-user experience as customers experience products with bugs&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, shift left testing by getting the testers involved early in the cycle helps in reducing costs involved in bug discovery and bug fixes. As a result, there is no delay or effect on the project’s final deliverables and even leads to customer satisfaction.&lt;/p&gt;

&lt;p&gt;To realize the potential of the shift left testing process in the field of &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt;, LambdaTest is hosting a webinar on Shift-Left Testing and Continuous Feedback to Deliver Quality at Agile Speed in association with Patrick Walsh — Engineering Manager at Teckro. Here’s a teaser for the same:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/P11fk8K3Xus"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/use-strict?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;ECMAScript 5 Strict Mode&lt;/strong&gt;&lt;/a&gt; — A strict alignment of code elements related to a particular topic is often used to visually reinforce the importance of that topic for the reader.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift Left and Shift Right in Software Testing
&lt;/h2&gt;

&lt;p&gt;Till now, we covered the essential fundamentals of shift right testing as well as shift left testing. While shift left testing ensures that lesser bugs make it to the production environment, the shift right testing approach ensures that issues discovered by end-users in the end-product are fixed at an expedited pace.&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1313608471233941504-354" src="https://platform.twitter.com/embed/Tweet.html?id=1313608471233941504"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1313608471233941504-354');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1313608471233941504&amp;amp;theme=dark"
  }



&lt;br&gt;
Both the testing approaches have their own significance and enterprises need to leverage the combination of shift right testing and shift left testing to improve product quality across the entire paradigm of product development. The intent should be to minimize the cost involved in discovering and fixing defects.&lt;/p&gt;
&lt;h2&gt;
  
  
  Advantages of Shift Left Testing approach
&lt;/h2&gt;

&lt;p&gt;We covered how you can avoid the risk of finding severe bugs at the end of the cycle by testing earlier in the cycle. However, that is not the only advantage that the shift left testing approach offers.&lt;/p&gt;

&lt;p&gt;Here are the salient benefits of shift left testing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reduced time to market since the overall QA process happens in a continuous manner&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced costs involved in fixing bugs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Top-notch product quality&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved customer experience due to a strong product base and lesser production issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved efficiency and reduced time in the overall software development lifecycle&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhts5qd3xqfc5afn6qmiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhts5qd3xqfc5afn6qmiw.png" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The ROI of Shift Left Testing
&lt;/h2&gt;

&lt;p&gt;As a QA manager, one of the key responsibilities should be to reduce the TAT (Turn Around Time) involved in bug discovery and bug fixing stages. Reduced TAT brings significant benefits across the entire value chain.&lt;/p&gt;

&lt;p&gt;The cost of detecting and fixing defects in software increases exponentially with time in the software development workflow. In simple terms, the later the bugs are found in the release cycle, the more expensive they turn out to be to fix. As a result, it costs much less to fix bugs that are discovered at an early stage.&lt;/p&gt;

&lt;p&gt;And guess what, fixing a bug that is found post-production costs approximately 30x more than it would have taken to fix it in in-house environments. Whoof!&lt;/p&gt;

&lt;p&gt;The below graph shows the relative cost of fixing bugs based on their time of detection, and as you can notice the cost increases exponentially with the lateness of their discovery&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2030%2F1%2AlUANV-Z0Ts2aKBaSz6Si-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2030%2F1%2AlUANV-Z0Ts2aKBaSz6Si-g.png" alt="[https://deepsource.io/blog/exponential-cost-of-fixing-bugs/](https://deepsource.io/blog/exponential-cost-of-fixing-bugs/)" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are the different types of Shift Left Testing?
&lt;/h2&gt;

&lt;p&gt;There are four different types of shift left testing that provide different values when performed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Traditional Shift Left Testing
&lt;/h2&gt;

&lt;p&gt;In order to understand the traditional shift left testing approach, we first must understand the traditional V-Model in a Software Development Life Cycle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDLC V-Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We already saw one of the most widely used SDLC models, which is the Waterfall model.&lt;br&gt;
The V-Model is an extension of the Waterfall model and is based on the association of a testing phase for each corresponding development stage. Therefore, it is also known as the Verification and Validation model. This means that there is a directly associated testing phase for every single phase in the development cycle. For example, the following image illustrates a typical V Model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACDMPaYG-RRanYp_4khHHJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACDMPaYG-RRanYp_4khHHJg.png" alt="[https://www.tutorialspoint.com/sdlc/sdlc_v_model.htm](https://www.tutorialspoint.com/sdlc/sdlc_v_model.htm)" width="800" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you know about the V Model. Let’s see what the traditional shift left testing process offers us.&lt;/p&gt;

&lt;p&gt;The traditional shift left testing process moves the testing lower down, hence, towards the left on the right side of the V Model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMKTN3w8C7agFqBCCf5C3zg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMKTN3w8C7agFqBCCf5C3zg.png" alt="[https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Traditional-Shift-Left.jpg](https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Traditional-Shift-Left.jpg)" width="800" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The traditional shift left testing process focuses more on Unit Testing and Integration Testing. This is done using API testing and achieved via the usage of &lt;a href="https://www.lambdatest.com/blog/everything-you-need-to-know-about-api-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;API testing&lt;/a&gt; and utilizing &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sept12_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; testing tools. It does not put more emphasis on acceptance testing &amp;amp; system-level testing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Incremental Shift Left Testing
&lt;/h2&gt;

&lt;p&gt;This shift left testing approach is most suitable for projects which are developing complex and large software systems. In such cases, it becomes difficult to manage all the tasks and deliverables together.&lt;/p&gt;

&lt;p&gt;Hence, they are broken down into smaller bits. These pieces are built upon each other, and with each increment, the software is also delivered to the customer. After each delivery, the development &amp;amp; testing is incrementally shifted to the left. Now, this helps even the testing teams as they can test each of the individual bits.&lt;/p&gt;

&lt;p&gt;Hence, it introduces incremental testing via an incremental development cycle. The below image is an illustration of Incremental shift left testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AmyG9BYkjvK2U1IWC-vh2Og.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AmyG9BYkjvK2U1IWC-vh2Og.png" alt="[https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Incremental-Shift-Left.jpg](https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Incremental-Shift-Left.jpg)" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The red dashed arrows indicate the shift left here since the bits of the large V Model are shifted left to become increments of the corresponding types of testing in the smaller incremental V Models. It introduces&lt;/p&gt;
&lt;h2&gt;
  
  
  Agile/DevOps Shift Left Testing
&lt;/h2&gt;

&lt;p&gt;This approach of shift left testing is usually done in a number of sprints. It emphasizes continuous testing via an evolutionary life cycle composed of many smaller sprints. It is mainly used for developmental testing and not for operational testing, which occurs once the system is operational.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AiFuUdJT6U9Qkv55FHJSaiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AiFuUdJT6U9Qkv55FHJSaiw.png" alt="[https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Agile_DevOps_Shift_Left_Testing.jpg](https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Agile_DevOps_Shift_Left_Testing.jpg)" width="800" height="614"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Model-Based Shift Left Testing
&lt;/h2&gt;

&lt;p&gt;The overall idea behind shift left testing is to catch bugs early before it becomes too late. However, in the above three models that we discussed, testing would start at the early stage of the development cycle. This leads to missing some of the critical issues of the requirement gathering phase, which later gets uncovered once the development cycle is over.&lt;/p&gt;

&lt;p&gt;Interestingly, around 45–65% of the defects are introduced during the requirement gathering phase, which we would miss in the above three models. In model-based shift left testing, testing can start at the earliest, so bugs are identified and solved long before the software development cycle starts. Imagine how helpful that would be. The below picture is an illustration of model-based shift left testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATTMCZBK6tWeJKcw47PGwJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATTMCZBK6tWeJKcw47PGwJg.png" alt="[https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Model-Shift-Left.jpg](https://en.wikipedia.org/wiki/Shift-left_testing#/media/File:Model-Shift-Left.jpg)" width="800" height="618"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to implement the Shift Left Testing approach?
&lt;/h2&gt;

&lt;p&gt;Here are some of the important steps that need to be implemented for rolling out a shift left testing strategy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Include Testers During Initial Plan And Analysis&lt;/strong&gt;: Requirement gathering is the most important phase in any software development life cycle. The testing team must get involved during the requirement analysis and gathering phase to have a thorough understanding of the requirements (and use cases). They must review, understand and analyze during this phase. This will lead to avoiding any ambiguity or confusion later in the cycle while testing the product.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Include Testers During Design And Development&lt;/strong&gt;: QA Teams must collaborate with the developers during the designing and development phase, providing them with the test scenarios that address all the customer use cases and business requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Develop A Robust &amp;amp; Strong Test Plan&lt;/strong&gt;: The testing team must develop a robust test plan to catch most of the defects during the initial phases and avoid finding critical issues during the actual testing phase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unified Test Strategy&lt;/strong&gt;: A unified test strategy helps the QA teams to analyze dependencies on the environment, automation, test data, etc., and helps in overall readiness. This strategy covers all the dimensions of Quality Control and helps define clear responsibilities for the individual team members.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Risk-Based Analysis&lt;/strong&gt;: This is usually done to examine each test scenario’s impact and the likelihood of failure. Once the test plan is ready, the testers must decide the priority of the test cases, and later, discuss with the developers the likelihood of that failure and the impact of that failure from the project manager.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Testing&lt;/strong&gt;: Static testing is carried out in the early phases of the project and includes validation of requirements and design. The purpose of static testing is to find defects early in the life cycle that could be very expensive to remove in the later phases of the project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Include Developers Into Testing Activities&lt;/strong&gt;: Developers must ensure that they test the individual units of code before sharing it with the concerned QA teams. This can easily address critical issues even before they are pushed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inculcate Test Automation&lt;/strong&gt;: Since shift left testing process involves continuous testing, repeating tests in every continuous cycle can be troublesome for both developers and testers. Hence, both teams should embrace test automation tools that can help them run the tests and ensure better code coverage and product quality.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With test automation, however, the problems of managing the automation suite and real devices arise. However, cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platforms like LambdaTest help you perform end-to-end automation tests on a secure, reliable, and scalable &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can perform automated cross browser testing with Selenium scripts on 3000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; and operating systems environments, giving you higher test coverage and significantly lesser built times. You could also run a single test across multiple browser/OS configurations simultaneously.&lt;/p&gt;

&lt;p&gt;This post on &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-for-cross-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cross Browser Testing In Selenium&lt;/a&gt; will help you quickly get started with Selenium automation testing on the LambdaTest Selenium automation grid. Hence, switching to LambdaTest can help you utilize the shift left testing capacity to its full benefit. Easy!&lt;/p&gt;

&lt;p&gt;You can go through the following video to have a quick demo of performing cross browser testing on the LambdaTest platform.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/na07BInGXpM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Also, you can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/adler32-hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr14_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Adler-32 Hash Calculator&lt;/a&gt; is a tool for computing the Adler-32 checksum of a string or file on your browser. The checksum, which can be generated in base64, hexadecimal, or integer formats, can be used to verify data integrity during transmission.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shortcomings of the Shift Left Testing approach
&lt;/h2&gt;

&lt;p&gt;We saw that there are so many key benefits of the shift left strategy. But we know everything comes with its own challenges. So here’s a limitation of the shift left testing approach:&lt;/p&gt;

&lt;p&gt;The major problem is that in order to shift left, the entire methodology needs to change, which would require a team effort. First, the managers and stakeholders need to start the plan from scratch and introduce it to the team members.&lt;/p&gt;

&lt;p&gt;Later, the team members need to adjust accordingly, which means a change in skill sets, tools, coding languages, etc. You see, that is a drastic change for anyone to get accustomed to! But once adopted, the benefits are enormous.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift Left Vs Shift Right? What is the way ahead?
&lt;/h2&gt;

&lt;p&gt;We read about shift right and how it helps discover all performance and usability issues in a production environment that can never be seen in a development or testing environment and improves the customer experience.&lt;/p&gt;

&lt;p&gt;On the other hand, the shift left helps us save time, effort, risk, and resources enormously. And the million-dollar question arises? Which one is better or which one to look for?&lt;/p&gt;

&lt;p&gt;Honestly, I feel these two testing methods are amazing and have their own set of benefits. Opting for any of these would enormously help you. However, why not merge both?&lt;br&gt;
By shifting our testing left and simultaneously shifting our testing right, we can test at every stage of the software development cycle, which will help us achieve continuous testing even better. Isn’t that amazing?&lt;/p&gt;

&lt;p&gt;Reach out to your QA, Development, and DevOps team members, and you can probably figure out a plan on how to include both in your release cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article on shift left testing, we read about what is shift left testing, what are the different types of it, its pros and cons, and how to implement it. In a nutshell, the shift left testing process is all about finding defects earlier, thereby reducing the overall cost, testing continuously to reduce defects in the end, and as a result, improving the customer experience. We also read about shift right and how it differs from shift left.&lt;/p&gt;

&lt;p&gt;Shift left testing has brought a huge change when it comes to the testing world. For testers, the core concept till now was just defect detection. However, the shift left testing process has introduced the concept of early defect detection and how it can lead to early defect prevention and, as a result, reap benefits for the entire team.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading the article and learned some more about the shift left testing&lt;br&gt;
approach.&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>tutorial</category>
      <category>agile</category>
      <category>devops</category>
    </item>
    <item>
      <title>Guide To Selenium WebDriver: Getting Started With Test Automation [Tutorial]</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Wed, 13 Apr 2022 10:26:40 +0000</pubDate>
      <link>https://forem.com/testmuai/guide-to-selenium-webdriver-getting-started-with-test-automation-tutorial-2330</link>
      <guid>https://forem.com/testmuai/guide-to-selenium-webdriver-getting-started-with-test-automation-tutorial-2330</guid>
      <description>&lt;p&gt;When it comes to &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;web automation testing&lt;/a&gt;, there are a number of frameworks like &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.&lt;/p&gt;

&lt;p&gt;For starters, Selenium WebDriver is the core of the Selenium automation framework. In this Selenium WebDriver tutorial, I deep dive into the integral aspects of Selenium WebDriver along with touching upon the Selenium WebDriver architecture.&lt;/p&gt;

&lt;p&gt;By the end of this Selenium WebDriver tutorial, you will be in a better position to run Selenium WebDriver tests on local Selenium Grid and cloud &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Selenium?
&lt;/h2&gt;

&lt;p&gt;Selenium is one of the most widely used open-source Web UI (User Interface) automation testing frameworks. It enables testers to execute tests across different browsers, platforms, and languages.&lt;/p&gt;

&lt;p&gt;During my QA career, I had the fortune to try out and use a number of test automation frameworks. So far, none of the frameworks come close to the Selenium automation framework in terms of framework features, supported languages, CI/CD integrations, and more. Nevertheless, as per a survey, Selenium automation testing is still the most preferred mode for realizing web automation testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ARC2ReIgaBMO2u-M1EEJQMg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ARC2ReIgaBMO2u-M1EEJQMg.png" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selenium is one-up concerning other test automation frameworks, as it provides compatibility with popular programming languages like Python, Java, JavaScript, C#, and Ruby. Therefore, referring to individual Selenium language tutorials like the &lt;a href="https://www.lambdatest.com/learning-hub/python-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Python tutorial&lt;/a&gt; can be a good starting point to make the most out of Selenium and Python for web automation testing.&lt;/p&gt;

&lt;p&gt;Shown below is the evolution of the Selenium automation framework:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2748%2F1%2A2f0xX_6-xWN5lGjHZjZEHQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2748%2F1%2A2f0xX_6-xWN5lGjHZjZEHQ.png" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apart from Selenium WebDriver, &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; and Selenium Grid are other key components of the Selenium framework. &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium 4&lt;/a&gt; is the latest Selenium version at the time of writing this blog. If you are curious about Selenium 4, you can further deep-dive into our blog on &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is new in Selenium 4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mmp_FiNIYtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Also, you can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; testing, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of Selenium automation framework
&lt;/h2&gt;

&lt;p&gt;Now that we have covered the basics about what is &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;, lets me walk you through some of the major features of the Selenium automation framework in this section of the Selenium WebDriver tutorial:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Selenium supports popular programming languages like Java, Python, C#, JavaScript, Ruby, PHP, and Perl; through the use of specific browser drivers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium is also a platform-agnostic test automation framework. For example, running &lt;a href="https://www.lambdatest.com/blog/selenium-safaridriver-macos/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium tests on macOS&lt;/a&gt; is very much similar to running Selenium tests on Windows OS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium tests can be executed across multiple browsers (e.g., Firefox, Chrome, IE, Safari, etc.) and multiple operating systems (e.g., Windows 10, macOS, etc.). &lt;a href="https://www.lambdatest.com/blog/how-to-run-selenium-tests-using-ie-driver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Running Selenium tests in IE&lt;/a&gt; is still relevant even in 2021 🙂&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parallel testing in Selenium&lt;/a&gt; using the Selenium Grid helps achieve improved browser and test coverage. This eventually helps in expediting the time to market.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium integration with test automation frameworks supported by Python, Java, JavaScript, etc., helps make the most out of Selenium and the corresponding test automation framework. For example, the &lt;a href="https://www.lambdatest.com/blog/create-testng-project-in-eclipse-run-selenium-test-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG framework for Selenium&lt;/a&gt; helps achieve the best out of Selenium and TestNG frameworks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium and Continuous Integration lets QA engineers run Selenium automation tests as a part of the CI/CD pipeline. For example, &lt;a href="https://www.lambdatest.com/blog/jenkins-integration-with-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Continuous Integration with Jenkins&lt;/a&gt; helps run Selenium automation tests as a part of Jenkins pipelines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium integration with reporting platforms like Extent, Allure, etc., helps generate and manage test reports. In addition, &lt;a href="https://www.lambdatest.com/blog/best-reporting-tools-for-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;reporting tools in Selenium&lt;/a&gt; provide information about the overall behavior of tests, which helps improve the quality of tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/run-selenium-tests-in-docker/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Running Selenium tests in Docker&lt;/a&gt; containers cuts down the test execution time and minimizes the differences that might arise among different test environments (e.g., staging, production, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you already know &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is Selenium&lt;/a&gt;, let’s deep dive into various components of Selenium in the next section of this Selenium WebDriver tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the components of Selenium?
&lt;/h2&gt;

&lt;p&gt;As already stated, Selenium is a framework (i.e., it is not a single software but a suite composed of different components).&lt;/p&gt;

&lt;p&gt;Selenium is composed of the following components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Selenium IDE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium WebDriver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium Grid&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s important to understand these main components in depth before getting started with a hands-on in this Selenium WebDriver tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium IDE
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/run-selenium-ide-test-on-online-selenium-grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; is basically a Record/Run tool that is available as a browser plugin for Mozilla Firefox and Google Chrome. You need not have any programming language experience to work with the IDE.&lt;/p&gt;

&lt;p&gt;It follows a record-and-playback approach wherein you can record your test steps and export the tests in the preferred Selenium-supported programming language. These exported tests can then be used with Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;Selenium IDE in Selenium 4 is more than a playback &amp;amp; recording tool, the features of which can be leveraged to make the most out of Selenium automation testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Selenium WebDriver is an enhanced version of Selenium RC and overcomes the limitations faced in Selenium RC. It controls the browser by direct communication. It has a faster execution time as compared to IDE and RC.&lt;/p&gt;

&lt;p&gt;Selenium RC and WebDriver were merged into one single unit known as Selenium WebDriver 2.0. Over time it has been enhanced for more features and functionalities. In Selenium 3, the JSON Wire protocol was the primary mode of communication between the test code and web browser.&lt;/p&gt;

&lt;p&gt;With Selenium 4, JSON Wire protocol is replaced with W3C protocol, which means that encoding and decoding of test requests are no longer required in WebDriver W3C protocol. Therefore, as QA engineers, we can expect less flaky tests with &lt;a href="https://www.lambdatest.com/blog/selenium4-w3c-webdriver-protocol/#Advantages?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;W3C WebDriver Protocol&lt;/a&gt; in Selenium 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium Grid
&lt;/h2&gt;

&lt;p&gt;Selenium Grid enables the users to perform parallel test execution. It is used along with Selenium RC to run parallel tests across different browsers and machines.&lt;/p&gt;

&lt;p&gt;Users can run simultaneous tests in multiple environments, thereby saving a lot of time and expediting the time to market.&lt;/p&gt;

&lt;p&gt;Selenium Grid is based on the Hub-Node concept. Until Selenium 3, the Hub and Node jars had to be started separately. With Selenium 4, all the necessary dependencies are available in a single Jar file. Therefore, to use the &lt;a href="https://www.lambdatest.com/blog/selenium-grid-4-tutorial-for-distributed-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid on Selenium 4&lt;/a&gt;, you need not start the Hub and Node separately.&lt;/p&gt;

&lt;p&gt;That’s not all. Selenium Grid on Selenium 4 supports different operating modes like Standalone Mode, Hub &amp;amp; Node Mode, and Fully-Distributed Mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium WebDriver architecture
&lt;/h2&gt;

&lt;p&gt;In this Selenium WebDriver tutorial, we have covered the basics of Selenium and its components. Now, let’s try to understand Selenium WebDriver in a detailed manner.&lt;/p&gt;

&lt;p&gt;As mentioned earlier, Selenium WebDriver is an enhanced version of Selenium RC. It is a web framework that helps us in executing cross browser tests. It also allows us to choose a programming language to create the test scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium WebDriver architecture in Selenium 3
&lt;/h2&gt;

&lt;p&gt;The Selenium WebDriver architecture in Selenium 3 constitutes of four major components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Selenium Client Libraries/ Language Bindings&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JSON Wire Protocol&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Browser Drivers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real Browsers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Selenium Client Libraries
&lt;/h3&gt;

&lt;p&gt;In order to support multiple languages, Selenium developers have built the language bindings. For example, if you are writing your tests in Java, you can use the Java bindings. Client libraries can be downloaded from the official Selenium website.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSON Wire Protocol
&lt;/h3&gt;

&lt;p&gt;JSON is an abbreviated form of JavaScript Object Notation. It transfers the data between client and server. It provides support for data structures like objects and arrays, hence doing data reading and writing easier.&lt;/p&gt;

&lt;p&gt;It acts as a REST(Representational State Transfer) API to transfer information between the HTTP servers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2226%2F1%2ALYTdPUW5QI7fStqsHKs8gA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2226%2F1%2ALYTdPUW5QI7fStqsHKs8gA.png" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Browser Drivers
&lt;/h3&gt;

&lt;p&gt;In order to develop a secure connection with the browser, Selenium uses Drivers. Each browser has its own driver that hides the internal logic of the browser’s functionality.&lt;/p&gt;

&lt;p&gt;In addition, each automation language has a corresponding browser driver. The following series of actions are performed when a Selenium automation test is triggered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Every Selenium command generates a corresponding HTTP request, which is sent to the browser driver.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This request is routed through the HTTP Server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The HTTP Server now drives the instruction execution on the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The browser sends back the status to the HTTP Server, which forwards it to the automation script.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the browser drivers are ChromeDriver, GeckoDriver, MicrosoftEdge driver, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Browsers
&lt;/h3&gt;

&lt;p&gt;Browsers are the end-point of our test execution. Selenium supports all major browsers like Firefox, Chrome, Safari, Edge, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium WebDriver architecture in Selenium 4
&lt;/h2&gt;

&lt;p&gt;One of the major differences between Selenium 3 and Selenium 4 is that Selenium WebDriver in Selenium 4 is W3C Compliant. As seen in the WebDriver architecture in Selenium 3, encoding and decoding of API requests had to be done due to the involvement of the JSON Wire protocol.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALDGwLy5c-zntAT8UGYl4_A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ALDGwLy5c-zntAT8UGYl4_A.png" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://www.lambdatest.com/blog/selenium4-w3c-webdriver-protocol/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;W3C WebDriver in Selenium 4&lt;/a&gt;, the tests can directly communicate with the web browser. Since the Selenium WebDriver and web browsers are on the same page (as far as W3C protocol is concerned), you can expect less flakiness and more consistency as far as Selenium automation testing is concerned.&lt;/p&gt;

&lt;p&gt;This certification is ideal for testing professionals who want to acquire advanced, hands-on knowledge in Selenium automation testing.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Advanced certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/DK21aHjuUE4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Now that we know about the entire architecture of Selenium WebDriver, let’s take a quick look at its advantages in this part of the Selenium WebDriver tutorial.&lt;/p&gt;

&lt;p&gt;Here are the major advantages of Selenium WebDriver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It supports multiple operating systems like Windows, Mac, Linux, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It supports multiple programming languages like Java, Python, JavaScript, PHP, C#, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is compatible with all modern browsers like Chrome, Firefox, Opera, Safari, and Microsoft Edge. It is also compatible with the near-retiring Internet Explorer (IE) browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides faster completion of test scripts as compared to other tools.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Limitations of Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/13-reasons-why-selenium-webdriver-should-be-your-first-choice-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;advantages of Selenium WebDriver&lt;/a&gt; outnumber its shortcomings. However, as a QA engineer, it is important to make an informed choice before choosing the best-suited framework for the project.&lt;/p&gt;

&lt;p&gt;Here are some of the potential shortcomings of Selenium WebDriver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It does not support the automation of Windows-based applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It does not have any in-built reporting mechanism.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no test tool integration for test management in Selenium.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Out of the box, Selenium WebDriver does not support parallel testing, which makes it very challenging to run larger and complex test suites. If you wish to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing with Selenium&lt;/a&gt;, then you need to use the Selenium Grid.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, you can eliminate the above-mentioned drawbacks by adopting &lt;a href="https://www.lambdatest.com/blog/cloud-selenium-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; for test automation where Selenium tests can securely run at scale, that too at a rapid pace! &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cross browser testing&lt;/a&gt; platforms like LambdaTest provide a secure, scalable, and reliable &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt; that lets you run Selenium tests in parallel on 2,000+ browser and platform configurations.&lt;/p&gt;

&lt;p&gt;In the latter sections of this Selenium WebDriver tutorial, we will deep dive into how to run Selenium tests in parallel on LambdaTest cloud Selenium Grid.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/array-find-index?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;Array.prototype.findIndex&lt;/strong&gt;&lt;/a&gt; - The method of &lt;code&gt;findIndex()&lt;/code&gt; returns an index of the 1st element in the array which aceepts the testing function provided.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium WebDriver: Installation and set up
&lt;/h2&gt;

&lt;p&gt;In this section of the Selenium WebDriver tutorial, we look at setting up Selenium WebDriver for the Windows Operating System with Java as the programming language.&lt;/p&gt;

&lt;p&gt;For demonstration, I have used the Eclipse IDE. However, you can choose to use the IDE of your choice. Now we are about to get our hands dirty with some code 🙂&lt;/p&gt;

&lt;p&gt;Starting with the prerequisites:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Install Java&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Eclipse IDE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Selenium WebDriver&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Install Java
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Go to the official &lt;a href="https://www.oracle.com/java/technologies/downloads/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Java Downloads website&lt;/a&gt; and download the JDK for Windows x64 Installer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2592%2F1%2Alj5RbZNbsP8qlnBB81Xa0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2592%2F1%2Alj5RbZNbsP8qlnBB81Xa0w.png" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Accept the license agreement in the pop-up next and click on Download.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AIeZNHe2U4OhDh-G_QygkDw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AIeZNHe2U4OhDh-G_QygkDw.png" width="769" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Once the download is done, navigate to the Downloads folder and double click the executable so that Java is installed in your system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set Up Environment Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Open your PC settings and select ‘Advanced system settings’ from the System dialog window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2238%2F1%2A08_JfZSUHQWTmCdqYITDMA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2238%2F1%2A08_JfZSUHQWTmCdqYITDMA.png" width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Click on the Environment Variables button on the next window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmc9ok86a3cak4yr5qpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmc9ok86a3cak4yr5qpt.png" width="417" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Now, under the System variables, double-click on Path.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK4Nss015Ejo-5oVPbQ5j_w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK4Nss015Ejo-5oVPbQ5j_w.png" width="597" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Add the complete path of the Java installation directory as per your system location and click OK.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU0HqLXbaFGVP_y_AlEqx4Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU0HqLXbaFGVP_y_AlEqx4Q.png" width="515" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: That’s it. You can now see the topmost path in the screenshot is the Java path in my system.&lt;/p&gt;

&lt;p&gt;To verify that the Java is installed and variables are set correctly, open Command Prompt and type: java -version. You will see the Java version installed in your system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AOAzFRjjBHdOCzexFymuiDw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AOAzFRjjBHdOCzexFymuiDw.png" width="678" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there you go, your first prerequisite is fulfilled. The next step is installing Eclipse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Eclipse
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Download Eclipse IDE for Java Developers from the &lt;a href="https://www.eclipse.org/downloads/packages/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;official Eclipse website&lt;/a&gt;. I would suggest downloading the last stable release. Select the download based on your system architecture. I am using eclipse Mars, but you can choose any of the latest versions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Once the download is complete, extract the zip file at a location at your convenience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoRK7kVErMH0QHaMgRVVHNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AoRK7kVErMH0QHaMgRVVHNQ.png" width="643" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Now open the extracted folder and double click on eclipse.exe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMk3W08BsGralh9sqhQRvrA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMk3W08BsGralh9sqhQRvrA.png" width="798" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Eclipse will open up, and there you are done with your second prerequisite of this Selenium WebDriver tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;The last step in this Selenium WebDriver tutorial is to install the Selenium Standalone Server, which is shown in the steps below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Download Selenium Client &amp;amp; WebDriver Language Bindings from the Selenium website. You can download the client libraries corresponding to your language preference. We will be working with Java Client Bindings in this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2446%2F1%2AlJzJjHm_NTDc85DWpzTZrQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2446%2F1%2AlJzJjHm_NTDc85DWpzTZrQ.png" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Once the file is downloaded, extract it to a folder of your choice from where you can use it later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3w-vWvMBYYuyR3lC-xS41g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3w-vWvMBYYuyR3lC-xS41g.png" width="643" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: You can now see the corresponding extracted file at the selected destination folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZ79MdJyh8U3W4e08ryiwvQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AZ79MdJyh8U3W4e08ryiwvQ.png" width="672" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: On opening the folder, you will be able to see the jar files, a libs folder(which contains some more jar files), and a CHANGELOG file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGKIeooUKaMHDLe2COzPAxA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGKIeooUKaMHDLe2COzPAxA.png" width="730" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Next, you need to download the browser drivers that will help you instantiate the browser. Below are the links to download the drivers for some major browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/mozilla/geckodriver/releases?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;GeckoDriver(Firefox)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://selenium-release.storage.googleapis.com/index.html?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;InternetExplorerDriver&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://sites.google.com/a/chromium.org/chromedriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ChromeDriver&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;difference between WebDriver and Remote WebDriver&lt;/a&gt; since there is no necessity to download browser drivers when running Selenium tests on a cloud Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: Next, simply extract the downloaded driver and store it at a location where you can use it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A14mK4NP7F_NDSl_UaeU4aA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A14mK4NP7F_NDSl_UaeU4aA.png" width="678" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are done with setting up the prerequisites, let’s look at how to configure Eclipse with the Selenium Libraries that we have just installed.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/array-includes?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;Array.prototype.includes&lt;/strong&gt;&lt;/a&gt; - Checks if an array includes the given value, returning a boolean value (unlike indexOf).&lt;/p&gt;

&lt;h2&gt;
  
  
  How to setup Eclipse for Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;The following steps in this Selenium WebDriver tutorial will guide you in configuring and installing the Eclipse IDE:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Launch eclipse.exe that was saved in the steps to install Eclipse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Select your workspace manually, or let the default location be there and click on OK.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2KpRn1geuqYJ8_uy7QML8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2KpRn1geuqYJ8_uy7QML8w.png" width="613" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Create a New Project by navigating to &lt;strong&gt;File &amp;gt; New &amp;gt; Java Project&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxkdhY_OAm17s-scclQiW1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxkdhY_OAm17s-scclQiW1w.png" width="547" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqFu-HNAW30BM-UQCqYHO-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqFu-HNAW30BM-UQCqYHO-g.png" width="517" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Click on Next and give a name to the Project. Click on Finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AX18U91ehMln6xYqIalJMOA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AX18U91ehMln6xYqIalJMOA.png" width="540" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Now that your project is created, Right-click on the project and select New &amp;gt; Package.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVbkxXzu3oS3QUa2678qr7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVbkxXzu3oS3QUa2678qr7g.png" width="642" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: Enter the package name in the New Java Package dialog box and click on Finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHJW1vzfNEFrF_w90Vtcrxw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHJW1vzfNEFrF_w90Vtcrxw.png" width="503" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7&lt;/strong&gt;: You need to create a class under the package now. To do so, right-click on the package name, go to New &amp;gt; Class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATatek4BYxczZmJovo8alsw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ATatek4BYxczZmJovo8alsw.png" width="674" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8&lt;/strong&gt;: In the New Java Class dialog box, enter a name for your class, select a method stub viz, public static void main(String[] args) and click on Finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtJmW8kwxaSP5TQtaf6KX-Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtJmW8kwxaSP5TQtaf6KX-Q.png" width="424" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your Explorer would look like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa69pd1rmxitn5x0zs36l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa69pd1rmxitn5x0zs36l.png" width="244" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9&lt;/strong&gt;: Now that we have created an outline for our test project, we need to import the libraries we installed for the Selenium WebDriver tutorial in the section above.&lt;/p&gt;

&lt;p&gt;To start with, right-click on the project and go to Build Path &amp;gt; Configure Build Path.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ap5DATk27aE5-IMc0J3-FgA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ap5DATk27aE5-IMc0J3-FgA.png" width="618" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 10&lt;/strong&gt;: Click on Add External JARs and navigate to the location where your downloaded JARs were saved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK6etv5vP1wCPGHmVWFjEXA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK6etv5vP1wCPGHmVWFjEXA.png" width="712" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 11&lt;/strong&gt;: Select the two jars installed in the Selenium Client folder and the jars under the libs folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ar_PT5XDM6tgFeLt-nuqhhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ar_PT5XDM6tgFeLt-nuqhhg.png" width="566" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AI0IDW0Z3eGjLjNy8lpGuig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AI0IDW0Z3eGjLjNy8lpGuig.png" width="570" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 12&lt;/strong&gt;: Once added, you will see the jar files under the Libraries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_v693UhOCB7ERvTyAdLp9A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_v693UhOCB7ERvTyAdLp9A.png" width="530" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 13&lt;/strong&gt;: Click on Apply and then OK. You can now see the Referenced Libraries populated in the package explorer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVJqGINCNZmJVt3Akc5LezA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVJqGINCNZmJVt3Akc5LezA.png" width="518" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have now configured Selenium WebDriver in our Eclipse Project and are good to write our first test script.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running test automation script using Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Now that I have touched upon Selenium Webdriver and its architecture, let’s write our first automation script using Selenium Webdriver in this section of the Selenium WebDriver tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem Statement
&lt;/h3&gt;

&lt;p&gt;To demonstrate the usage of Selenium WebDriver, I will perform the following use case:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch Chrome browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest sign up page&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Sign In button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the web browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({util.Listener.class})
class FirstTestScriptUsingWebDriver {
   public static WebDriver driver = null;
   @BeforeTest
   public void setUp() throws Exception {
       WebDriverManager.chromedriver().setup();
       driver=new ChromeDriver();
   }
   @Test
   public void firstTestCase() {
       try {
           System.out.println("Logging into Lambda Test Sign Up Page");
           driver.get("https://accounts.lambdatest.com/register");
           WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']"));
           pageHeader.click();
           System.out.println("Clicked on the Sign In Button.");
       } catch (Exception e) {
       }
   }
   @AfterTest
   public void closeBrowser() {
       driver.close();
       System.out.println("The driver has been closed.");
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will need the below pom.xml for importing the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
  &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

  &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
  &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
  &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
  &amp;lt;dependencies&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
      &amp;lt;/dependency&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
      &amp;lt;/dependency&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
      &amp;lt;/dependency&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
      &amp;lt;/dependency&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
      &amp;lt;/dependency&amp;gt;
  &amp;lt;/dependencies&amp;gt;

  &amp;lt;properties&amp;gt;
      &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
      &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
  &amp;lt;/properties&amp;gt;
&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the below testng.xml file will be needed for running the test case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="FirstTestScriptUsingWebDriverSuite"&amp;gt;
   &amp;lt;test name="FirstTestScriptUsingWebDriver" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LambdaTest.FirstTestScriptUsingWebDriver" &amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="FirstTestScriptUsingWebDriverSuite"&amp;gt;
   &amp;lt;test name="FirstTestScriptUsingWebDriver" &amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="LambdaTest.FirstTestScriptUsingWebDriver" &amp;gt;
           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Import Dependencies: Here, we have imported all the necessary classes for using WebDriver, ChromeDriver, and the related &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;annotations in TestNG&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARIVYvAF47G53SCBc6Hdo6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ARIVYvAF47G53SCBc6Hdo6A.png" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@BeforeTest&lt;/strong&gt;: Typically, for running any Selenium test script, you will need a browser driver, and to use it, you need to set the browser driver executable path explicitly. After that, you need to instantiate the driver instance and proceed with the test case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3ybezsd606zatlu3t0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3ybezsd606zatlu3t0r.png" width="750" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, managing the browser driver can become cumbersome over time as their versions keep changing, and you need to keep updating the drivers. Hence, to overcome the same, I have used the WebDriverManagerClass.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUBdmLUVQjQu8fZqtF_E4uw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUBdmLUVQjQu8fZqtF_E4uw.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, WebDriverManager.chromedriver.setup() checks for the latest version of the specified web driver binary. If the binaries are not present, it will download them and later instantiate the Selenium WebDriver instance with the ChromeDriver. Isn’t it easy? 🙂&lt;/p&gt;

&lt;p&gt;The below two classes will help you in using WebDriver and ChromeDriver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXYQoxVlakYCcuwzQhdlFeg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AXYQoxVlakYCcuwzQhdlFeg.png" width="800" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@ Test(firstTestCase)&lt;/strong&gt;: In the test case, I opened the &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest sign up page&lt;/a&gt; in the Chrome browser using the driver.get() statement. The findElement method in Selenium is used for locating the SignIn WebElement.&lt;/p&gt;

&lt;p&gt;Here, I have used &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt; for locating the ‘Sign In’ button. To investigate the XPath of any element, you can simply right-click on it and click on Inspect. You will be able to spot the locator in the Elements tab. The &lt;a href="https://www.lambdatest.com/blog/selenium-click-button-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;click method in Selenium&lt;/a&gt; is used for clicking on the Sign In button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AsyOIcKtfsM-xb9581dChlQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AsyOIcKtfsM-xb9581dChlQ.png" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@AfterTest&lt;/strong&gt;: In the AfterTest method, close the browser using the driver.close() method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2272%2F1%2AEv7f712ujoCy4nbESfRIvA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2272%2F1%2AEv7f712ujoCy4nbESfRIvA.png" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You will see the below output once you run the testng.xml file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ADjUHIZofQ47xnOl7XB6Mzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ADjUHIZofQ47xnOl7XB6Mzg.png" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automated browser testing using cloud Selenium Grid
&lt;/h2&gt;

&lt;p&gt;So far, in this Selenium WebDriver tutorial, I used the local Selenium WebDriver to run a particular test case. Now, as the number of test cases increases, running them parallel with a higher number of threads on a single VM would start giving automation failures.&lt;/p&gt;

&lt;p&gt;However, a realistic scenario is where a single test case (or multiple test cases) has to be run across different browser and OS combinations. This is where the &lt;a href="https://www.lambdatest.com/blog/why-selenium-grid-is-ideal-for-automated-browser-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid&lt;/a&gt; comes into the picture. Selenium Grid eases our setup-related woes, along with helping us run tests at scale on a local (or cloud) grid setup.&lt;/p&gt;

&lt;p&gt;Selenium Grid makes parallel execution possible by sending commands to remote Web Browser instances from a hub server.&lt;/p&gt;

&lt;p&gt;Selenium testing tools like LambdaTest offer a cloud Selenium Grid that lets you run parallel tests across 3000+ different browsers and operating systems. All you need to do is instantiate the remote Selenium WebDriver instead of the local Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;With LambdaTest, you don’t have to worry about downloading and configuring hundreds of browsers on your machine as they are readily available on the online Selenium Grid. Instead, all you need to do is &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;register on LambdaTest&lt;/a&gt; for free and claim your 100 free automation testing minutes.&lt;/p&gt;

&lt;p&gt;Now that I have covered the basics of cloud Selenium Grid, let’s implement the same example using LambdaTest Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the below example, I am running the same test case on Chrome (latest) + Windows 10 combination.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch Chrome browser on Windows 10&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest sign up page&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Sign In button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the web browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class FirstTestScriptUsingSeleniumGrid {

  public String username = "YOUR USERNAME";
  public String accesskey = "YOUR ACCESSKEY";
  public static RemoteWebDriver driver = null;
  public String gridURL = "@hub.lambdatest.com/wd/hub";

  @BeforeTest
  public void setUp() throws Exception {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("browserName", "chrome");
      capabilities.setCapability("version", "94.0");
      capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
      capabilities.setCapability("build", "FirstTestScript");
      capabilities.setCapability("name", "FirstTestScriptSample");
      try {
          driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
      } catch (MalformedURLException e) {
          System.out.println("Invalid grid URL");
      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  }

  @Test
  public void firstTestCase() {
      try {
          System.out.println("Logging into Lambda Test Sign Up Page");
          driver.get("https://accounts.lambdatest.com/register");
          WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']"));
          pageHeader.click();
          System.out.println("Clicked on the Sign In Button.");
      } catch (Exception e) {

      }
   }

  @AfterTest
  public void closeBrowser() {
      driver.close();
      System.out.println("The driver has been closed.");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Variables&lt;/strong&gt;: As tests have to be run on LambdaTest cloud Selenium Grid, we would be using the below-shown variables.&lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LamdaTest Profile Section&lt;/a&gt;. However, the gridURL will remain the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2148%2F1%2ArYBeL4XiWawAPHTMI0V85A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2148%2F1%2ArYBeL4XiWawAPHTMI0V85A.png" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@BeforeTest(Setup Method)&lt;/strong&gt;: In Selenium, the RemoteWebDriver class implements the WebDriver interface to execute test scripts through the RemoteWebDriver server on a remote machine.&lt;/p&gt;

&lt;p&gt;The below-imported class will help you in using the RemoteWebDriver class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5dqs8rpvc47r61t9bae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5dqs8rpvc47r61t9bae.png" width="800" height="258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AjBAOAIP6aQvToWdYLwrVMA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AjBAOAIP6aQvToWdYLwrVMA.png" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The implementation under @ Test and @AfterTest annotations remain unchanged since only the end-point of execution have changed from Selenium Grid’s load to cloud Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Log on to &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt; to check the status of the test execution on LambdaTest.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxm7wzh2bayn95rr8o0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxm7wzh2bayn95rr8o0v.png" width="800" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/asmjs?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;asm.js&lt;/strong&gt;&lt;/a&gt; - The asm.js subset of JavaScript provides low-level, portable performance with high-level language semantics. Asm.js is intended to be a target for a compile step from languages like C/C++ into optimized JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s new in Selenium WebDriver 4?
&lt;/h2&gt;

&lt;p&gt;So far, in this Selenium WebDriver tutorial, I have covered the essentials of Selenium WebDriver and its architecture in Selenium 3 and Selenium 4. However, as a QA engineer, the innumerable features offered by Selenium 4 fascinate me a lot!&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1448289975062220808-244" src="https://platform.twitter.com/embed/Tweet.html?id=1448289975062220808"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1448289975062220808-244');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1448289975062220808&amp;amp;theme=dark"
  }



&lt;br&gt;
Apart from the renewed Selenium WebDriver architecture, here are some of the other major enhancements in Selenium 4:&lt;/p&gt;
&lt;h2&gt;
  
  
  W3C Standardization
&lt;/h2&gt;

&lt;p&gt;A significant change in Selenium 4 is the complete W3C compliance of the WebDriver APIs. This eliminates the need for encoding and decoding the API requests by the JSON wire protocol responsible for communication between browsers and test scripts.&lt;/p&gt;

&lt;p&gt;The implementation of this standardization means the WebDriver will now interact directly with the target browser.&lt;/p&gt;
&lt;h2&gt;
  
  
  Enhanced Selenium Grid
&lt;/h2&gt;

&lt;p&gt;The earlier versions of Selenium Grid were complex to set up and maintain. However, the new Selenium Grid is easy to set up as there is no need to maintain Hub and Node separately.&lt;/p&gt;

&lt;p&gt;The Grid even has an improved GUI, and the support for Docker helps the developers (and testers) to use it on Virtual Machines(VMs). The Grid can also be deployed now on Kubernetes. &lt;a href="https://www.lambdatest.com/blog/run-selenium-tests-in-docker/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Running Selenium tests in Docker&lt;/a&gt; is now a cakewalk with the Selenium Grid setup on Selenium 4!&lt;/p&gt;
&lt;h2&gt;
  
  
  Relative Locators in Selenium 4
&lt;/h2&gt;

&lt;p&gt;Relative locators (or Friendly locators) help locate WebElements relative to a particular WebElement. For example, the required element could be near to, left of, right of, above, or below a specified element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/selenium-4-relative-locator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Relative locators in Selenium 4&lt;/a&gt; can help save a lot of time when locating tricky WebElements. Above, Below, To Right Of, To Left Of, and Near are some of the relative locators that can be leveraged to reduce the lines of code when it comes to locating WebElements.&lt;/p&gt;
&lt;h2&gt;
  
  
  Better Browser and Tab Management
&lt;/h2&gt;

&lt;p&gt;Selenium 4 provides a new API newWindow that lets you create a new window (or tab) and switch to it without creating a new WebDriver object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opening a new Window in Selenium 4&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.get("https://www.google.com/");
// Opens a new window and switches to new window
driver.switchTo().newWindow(WindowType.WINDOW);
// Opens LambdaTest homepage in the newly opened window
driver.navigate().to("https://www.lambdatest.com/");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Opening a new Tab in Selenium 4&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.get("https://www.google.com/");
// Opens a new window and switches to new window
driver.switchTo().newWindow(WindowType.TAB);
// Opens LambdaTest homepage in the newly opened tab
driver.navigate().to("https://www.lambdatest.com/");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deprecation Of Desired Capabilities
&lt;/h2&gt;

&lt;p&gt;In Selenium 4, Desired Capabilities are getting replaced with Options, and we need to create an Options object to use the Driver class.&lt;/p&gt;

&lt;p&gt;The below-mentioned Options objects will be used in Selenium 4 for defining the browser-specific capabilities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chrome — ChromeOptions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firefox — FirefoxOptions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Safari — SafariOptions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Internet Explorer (IE) — InternetExplorerOptions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Microsoft Edge — EdgeOptions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Chrome DevTools Protocol (CDP)
&lt;/h2&gt;

&lt;p&gt;Chrome DevTools Protocol is the new addition in Selenium 4. The new feature provides Chrome and Microsoft Edge’s debugging protocol for debugging, simulating poor network conditions, and emulating geolocation for automation testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/geolocation-testing-with-selenium-using-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Geolocation testing with Selenium&lt;/a&gt; helps in mocking browser’s geolocation for the purpose of web browser testing. This feature in Selenium 4 can be leveraged to test the website’s functionalities by mocking different geographical locations.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/c08Z3HoSDCM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this Selenium WebDriver tutorial, I deep-dived into the basics of Selenium WebDriver, its components, and Selenium WebDriver architecture. I also implemented test scenarios using WebDriver as well as cloud Selenium Grid. In the end, we also glanced upon the new and improved features which Selenium 4 offers. I believe you are now all geared up to start on your Selenium automation journey.&lt;/p&gt;

&lt;p&gt;Happy testing! 🙂&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How To Minimize Browsers In Selenium WebDriver Using JUnit</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Tue, 12 Apr 2022 10:58:34 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-minimize-browsers-in-selenium-webdriver-using-junit-19m1</link>
      <guid>https://forem.com/testmuai/how-to-minimize-browsers-in-selenium-webdriver-using-junit-19m1</guid>
      <description>&lt;p&gt;Delivering software with superior UI is one of the key aspects of development, but there are times when you need to test the most complicated functionality. These tests include window resizing or minimizing or maximizing, all of which require interacting with the browser window, and if the number of tests is high, it becomes cumbersome. Minimizing browser windows in &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-junit?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium with JUnit&lt;/a&gt; can be used for automating interactions with browser windows. There are scenarios where minimization of browser windows is a must-have operation to proceed with other scenarios in the respective test suite.&lt;/p&gt;

&lt;p&gt;Another use case to run our tests with a minimized browser is when we are running tests on our local machine, and we want the screen to be free for us to do something else while the tests continue to run. Whatever the reason be, minimizing the browser window using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; is a very useful feature and can make our lives easier in many situations.&lt;/p&gt;

&lt;p&gt;Let’s take a deeper look at how you can handle minimized and maximized browser windows with Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;In our previous blogs of this &lt;a href="https://www.lambdatest.com/learning-hub/junit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium JUnit tutorial&lt;/a&gt; series, we have learned how to run &lt;a href="https://www.lambdatest.com/blog/junit-parameterized-test-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parameterized tests in JUnit&lt;/a&gt;, use &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;annotations in JUnit&lt;/a&gt;, and much more. In this Selenium JUnit tutorial, we will learn how to minimize browsers in Selenium WebDriver using JUnit.&lt;/p&gt;

&lt;p&gt;Starting your journey with Selenium WebDriver? Check out this step-by-step guide to perform Automation testing using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to minimize browsers in Selenium WebDriver using JUnit?
&lt;/h2&gt;

&lt;p&gt;Until Selenium 3, we had some limitations while handling the browsers; i.e., we were only able to maximize the window and not able to minimize directly. Though it allowed using setPosition() to minimize the browser window, it was of no use as you couldn’t maximize whenever you wanted.&lt;/p&gt;

&lt;p&gt;However, with &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium4&lt;/a&gt;, you have a new minimize() method that reduces browser windows to a taskbar icon, just like a user normally does. Like the “SwitchTo().window(id)” method, the minimize window is also accessible with the window.minimize() method in Selenium WebDriver 4.&lt;/p&gt;

&lt;p&gt;Selenium 4 brings out the immense potential offered by the Selenium framework. Selenium 4 is built to work better with technology stacks native to the browser, including modern JavaScript frameworks. If you want to know more about Selenium 4, you can further deep-dive into our blog on &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is new in Selenium 4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mmp_FiNIYtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Also, you can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;In order to minimize the browser window in our Selenium automation script, we can use the below-mentioned command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.manage().window().minimize();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For using the minimize function, we just need the corresponding Selenium WebDriver package. In our use case, it is RemoteWebDriver since we are running the cases on an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funywxv1s4zioi8l6g9pb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funywxv1s4zioi8l6g9pb.png" width="683" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have seen the syntax for minimizing the browser let’s deep dive into how we can use the same in our Selenium automation framework. We would do the same by demonstrating through a Minimize Browser Window example.&lt;/p&gt;

&lt;p&gt;We will make use of the LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; to automate our test cases.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; tool that provides a solution to every obstacle you face while performing automation testing using your local machine. Selenium testing tools like LambdaTest offer a Selenium Grid consisting of 2000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; for you to perform Selenium automation testing effortlessly.&lt;/p&gt;

&lt;p&gt;In the next section of this Selenium JUnit tutorial on how to minimize browsers in Selenium WebDriver, we will demonstrate how you could easily perform automation testing by making use of the cloud Selenium Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to minimize browser window in Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Log into the &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LambdaTest by launching the browser, followed by minimizing it and then getting the Page Title.&lt;/p&gt;

&lt;p&gt;We will cover the below-mentioned steps in our test case:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch the web browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com/selenium-playground/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minimize browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the web page title and print the same.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is the test class file and the pom.xml, which will be needed to install all the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;

class MinimizeBrowserWindow {
   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "95.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "MinimizeBrowserWindow");
       capabilities.setCapability("name", "MinimizeBrowserWindowUsingSelenium");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }

   }

   @Test
   public void minimizeBrowserWindow() {
       try {
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           driver.manage().window().minimize();
           System.out.println("Minimized the browser window");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
       } catch (Exception e) {

       }

   }


   @AfterClass
   public void closeBrowser() {
       driver.close();
       System.out.println("Closing the browser");

   }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below pom.xml will be needed for installing all the necessary dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

   &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
   &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
   &amp;lt;dependencies&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.10&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
   &amp;lt;/dependencies&amp;gt;

   &amp;lt;properties&amp;gt;
       &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
       &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
   &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/free-online-tools/json-unescape?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Unescape JSON&lt;/a&gt; is a JavaScript utility that restores an escaped JSON string or file back to its unescaped original state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;In this section of this Selenium JUnit tutorial on how to minimize browsers in Selenium WebDriverNow, let’s try to understand the test case using the &lt;a href="https://www.lambdatest.com/blog/how-to-use-testng-reporter-log-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG Reporter Log&lt;/a&gt;, which we automated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Import Dependencies&lt;/strong&gt;: Here, we have imported all the necessary classes of JUnit, Desired Capabilities, and RemoteWebDriver to set the respective browser capabilities and run the test cases on the grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fsaxgl9be7yilohiszc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fsaxgl9be7yilohiszc.png" width="720" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: As we have used a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid Cloud&lt;/a&gt; like LamdaTest to perform our test execution, we are using the below-shown variables. &lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LamdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ew2gm92apdzvnuppt05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ew2gm92apdzvnuppt05.png" width="699" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. @BeforeClass(Setup Method)&lt;/strong&gt;: Here, we have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Remote WebDriver&lt;/a&gt;. In case you are new to JUnit annotations, do check out &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Annotations in JUnit&lt;/a&gt; blog that deep dives into the important annotations in JUnit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. @ Test(minimizeBrowserWindow)&lt;/strong&gt;: Here, we are simply logging into &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt;, and then we are minimizing the browser using the driver.manage.window.minimize() command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyndltoc6t08fi0vtu2ub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyndltoc6t08fi0vtu2ub.png" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After minimizing the browser window, we get the title of the web page and print the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Console Output
&lt;/h2&gt;

&lt;p&gt;Once you run the test case, your console output will look like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxevv7y73buqbqbosmesv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxevv7y73buqbqbosmesv.png" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So as you can see, the test case runs seamlessly even when you minimize the actual browser window. Isn’t it cool?&lt;/p&gt;

&lt;p&gt;Start your free &lt;a href="https://www.lambdatest.com/remote-browser?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;testing on remote browser&lt;/a&gt; today.&lt;/p&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium automation testing with JUnit.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the JUnit certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fWsCwrtElAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to minimize browsers in Selenium WebDriver using JUnit by setting its position?
&lt;/h2&gt;

&lt;p&gt;In the above example of this Selenium JUnit tutorial, we saw how to minimize browsers in Selenium WebDriver using the minimize() function, which is one of the most widely used methods to do the same. However, wouldn’t it be interesting to explore a few more alternatives to do it? Let’s check them.&lt;/p&gt;

&lt;p&gt;In order to minimize the browser window, we can also use the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.manage().window().setPosition(new Point(int x,int y));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, x and y refer to the respective x and y coordinates of the window position. Since the window position and dimensions differ from one machine to another, we will use a generic method of finding out the corresponding x &amp;amp; y coordinates relevant to the browser window. In the end, we will use them for setting the minimized position.&lt;/p&gt;

&lt;p&gt;The below test case demonstrates the same use case that was demonstrated earlier. The only change is the usage of setPosition method to minimize the corresponding browser window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;

class MinimizeBrowserWindowUsingPosition {

   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "95.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "MinimizeBrowserWindowBySettingPosition");
       capabilities.setCapability("name", "MinimizeBrowserWindowBySettingPositionUsingSelenium");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }

   }

   @Test
   public void minimizeBrowserWindowBySettingPosition() {
       try {
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           Point p = driver.manage().window().getPosition();
           System.out.println("The Position of the window is:"+p);
           Dimension d = driver.manage().window().getSize();
           System.out.println("The Size of the window is:"+d);
           driver.manage().window().setPosition(new Point((d.getHeight()-p.getX()), (d.getWidth()-p.getY())));
           System.out.println("The New X Coordinate After Minimizing Is:"+(d.getHeight()-p.getX()));
           System.out.println("The New Y Coordinate After Minimizing Is:"+(d.getWidth()-p.getY()));
           System.out.println("Minimized the browser window by setting its position");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
       } catch (Exception e) {

       }

   }


   @AfterClass
   public void closeBrowser() {
       driver.close();
       System.out.println("Closing the browser");
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;Window position means the distance of the window from the left side(X Coordinates) of the screen and topside(Y Coordinates) of the screen.&lt;/p&gt;

&lt;p&gt;We are first determining the Position of the window followed by the Dimension. Later, by using the setPosition method, we set the corresponding x and y coordinates of the window as shown below, which will minimize the window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.manage().window().setPosition(new Point((d.getHeight()-p.getX()), (d.getWidth()-p.getY())));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The below-highlighted package imports are necessary to use the Dimension and Point methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtcA7OFhg92jHVGlETHBfqQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AtcA7OFhg92jHVGlETHBfqQ.png" width="707" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2696%2F1%2AWC1qrhSSgULe1I2SPFjT3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2696%2F1%2AWC1qrhSSgULe1I2SPFjT3g.png" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Console Output
&lt;/h2&gt;

&lt;p&gt;Once you run the test case, your console output will look like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxh4ia4ep1jabjazlemh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxh4ia4ep1jabjazlemh.png" width="800" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to minimize browsers in Selenium WebDriver using keyboard shortcuts?
&lt;/h2&gt;

&lt;p&gt;In the above two sections of this Selenium JUnit tutorial, we looked at how to minimize browsers in Selenium WebDriver using the driver.manage.window() commands.&lt;/p&gt;

&lt;p&gt;However, when it comes to minimizing the windows manually, we always fall back on keyboard shortcuts. The most widely used keyboard shortcut for doing the same is Windows + D.&lt;/p&gt;

&lt;p&gt;Let’s see how we can replicate the keyboard shortcuts using our Selenium automation script. In this use case of replicating the keyboard shortcuts, we will make use of the Robot Class. Robot Class in Selenium generates native system input events for &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; and other applications where you need control over the mouse and keyboard. The major benefit of Robot Class is that it helps to handle &lt;a href="https://www.lambdatest.com/blog/handling-keyboard-actions-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;keyboard actions in Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, one thing important to note is that the below use case of minimizing the browser using keyboard shortcuts holds only for a Windows Machine.&lt;/p&gt;

&lt;p&gt;The below test case demonstrates the same use case for how to minimize browsers in Selenium WebDriver and getting the web page title with minimized browser window using the keyboard shortcut.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.net.MalformedURLException;
import java.net.URL;

class MinimizeBrowserWindowUsingRobotClass {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public static RemoteWebDriver driver = null;
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeClass
   public void setUp() throws Exception {
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("browserName", "chrome");
       capabilities.setCapability("version", "95.0");
       capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
       capabilities.setCapability("build", "MinimizeBrowserWindow");
       capabilities.setCapability("name", "MinimizeBrowserWindowUsingRobotClass");
       try {
           driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
       } catch (MalformedURLException e) {
           System.out.println("Invalid grid URL");
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }

   }

   @Test
   public void minimizeBrowserWindowUsingRobotClass() {
       try {
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           Robot robot = new Robot();
           robot.keyPress(KeyEvent.VK_WINDOWS);
           robot.keyPress(KeyEvent.VK_D);
           System.out.println("Minimizing the window");
           robot.keyRelease(KeyEvent.VK_WINDOWS);
           robot.keyRelease(KeyEvent.VK_D);
           System.out.println("Minimized the browser window");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
       } catch (Exception e) {

       }

   }


   @AfterClass
   public void closeBrowser() {
       driver.close();
       System.out.println("Closing the browser");

   }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;To emulate the keyboard shortcut(Windows + D), we have used Robot Class. Here, we have made use of keyPress and keyRelease functions of Robot Class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2408%2F1%2AceGlCp5_HobyWGnTUCAHLA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2408%2F1%2AceGlCp5_HobyWGnTUCAHLA.png" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;keyPress(int keycode)&lt;/strong&gt;: This method is used to press a given key. The parameter keycode is an integer value for the key pressed. For example, to press a key for alphabet A, the value that has to pass is KeyEvent.VK_A i.e., keyPress(KeyEvent.VK_A).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;keyRelease(int keycode)&lt;/strong&gt;: This method releases the given key. The keycode parameter is the integer value for the pressed key. For example, to release the already pressed key for alphabet A, the value that has to pass is KeyEvent.VK_A i.e., keyPress(KeyEvent.VK_A).&lt;/p&gt;

&lt;p&gt;Here, KeyEvent is a low-level event. In Java AWT, low-level events are events that indicate direct communication from the user like a keypress, key release, etc.&lt;/p&gt;

&lt;p&gt;In order to use the above-specified methods, you will need the below package imports.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5uv4oqc5k3ijm54ofgrk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5uv4oqc5k3ijm54ofgrk.png" width="460" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, by using the Robot class and its keyPress and KeyRelease methods, we would easily emulate the keyboard actions of pressing Windows+D buttons together and releasing them once the browser window gets minimized.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/link-icon-svg?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;SVG favicons&lt;/strong&gt;&lt;/a&gt; shows a browser compatibility score of &lt;strong&gt;40&lt;/strong&gt;. This is a collective score out of 100 to represent browser support of a web technology. The higher this score is, the greater is the browser compatibility. The browser compatibility score is not a 100% reflection for every browser and the web technology support. However, it does give you an estimate on how much you should rely on a particular web technology in terms of browser compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to minimize multiple browser windows in Selenium WebDriver using JUnit?
&lt;/h2&gt;

&lt;p&gt;In the above sections of this Selenium JUnit tutorial, we saw how to minimize browsers in Selenium WebDriver using different ways like using the minimize method, setPosition method, and the keyboard actions in Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;We would be demonstrating the same usecase in this section as well. However, we cover it through three different test methods in this example and perform it in three different browsers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;

class MinimizeMultipleBrowserWindow {


   public String username = "YOUR USERNAME";
   public String accesskey = "YOUR ACCESSKEY";
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @Test
   public void minimizeWindowInChromeBrowser() {
       try {
           RemoteWebDriver driver = null;
           DesiredCapabilities capabilities = new DesiredCapabilities();
           capabilities.setCapability("browserName", "Chrome");
           capabilities.setCapability("version", "latest");
           capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
           capabilities.setCapability("build", "MinimizeChromeBrowserWindow");
           capabilities.setCapability("name", "MinimizeChromeBrowserWindowUsingChromeBrowser");
           try {
               driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
           } catch (MalformedURLException e) {
               System.out.println("Invalid grid URL");
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           driver.manage().window().minimize();
           System.out.println("Minimized the browser window");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
           driver.close();
           System.out.println("Closing the browser");
       } catch (Exception e) {

       }

   }

   @Test
   public void minimizeWindowInFirefoxBrowser() {
       try {
           RemoteWebDriver driver = null;
           DesiredCapabilities capabilities = new DesiredCapabilities();
           capabilities.setCapability("browserName", "Firefox");
           capabilities.setCapability("version", "94.0");
           capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
           capabilities.setCapability("build", "MinimizeFirefoxBrowserWindow");
           capabilities.setCapability("name", "MinimizeFirefoxBrowserWindowUsingFireFoxBrowser");
           try {
               driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
           } catch (MalformedURLException e) {
               System.out.println("Invalid grid URL");
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           driver.manage().window().minimize();
           System.out.println("Minimized the browser window");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
           driver.close();
           System.out.println("Closing the browser");
       } catch (Exception e) {

       }

   }

   @Test
   public void minimizeWindowInMicrosoftEdgeBrowser() {
       try {
           RemoteWebDriver driver = null;
           DesiredCapabilities capabilities = new DesiredCapabilities();
           capabilities.setCapability("browserName", "MicrosoftEdge");
           capabilities.setCapability("version", "95.0");
           capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
           capabilities.setCapability("build", "MinimizeEdgeBrowserWindow");
           capabilities.setCapability("name", "MinimizeEdgeBrowserWindowUsingEdgeBrowser");
           try {
               driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
           } catch (MalformedURLException e) {
               System.out.println("Invalid grid URL");
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
           System.out.println("Logging into Selenium Playground");
           driver.get("http://labs.lambdatest.com/selenium-playground/");
           driver.manage().window().minimize();
           System.out.println("Minimized the browser window");
           String title=driver.getTitle();
           System.out.println("The title of web page is:"+title);
           driver.close();
           System.out.println("Closing the browser");
       } catch (Exception e) {

       }

   }


}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;In this test case, we cover the minimized window functionality in three different browsers, i.e., Chrome, Firefox, and Microsoft Edge. Here, we are using the LambdaTest grid to set up the corresponding browser name and versions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2784%2F1%2AHy_dKIoC94w9-oRCXZ9lVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2784%2F1%2AHy_dKIoC94w9-oRCXZ9lVg.png" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the corresponding browsers are launched, we log into &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt;, minimize the corresponding windows, and get the web page title.&lt;/p&gt;

&lt;p&gt;As a result, by using the LambdaTest grid, we covered the same test case in 3 different browser flavors. We then ran the three different test cases simultaneously by making use of &lt;a href="https://www.lambdatest.com/blog/parallel-testing-with-junit5-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing with JUnit 5 and Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Life is easier, isn’t it?&lt;/p&gt;

&lt;p&gt;This &lt;a href="https://www.youtube.com/playlist?list=PLZMWkkQEwOPn68qzCGJl07ZbnI7Ix5zKU?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium JUnit testing tutorial&lt;/a&gt; for beginners and professionals will help you perform parallel test execution with JUnit and Selenium on LambdaTest cloud-based Selenium Grid.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IBWJCk2SHYk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can view the test results, logs, and the test recording as well at your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fft4wnzxt0sx6e52yylvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fft4wnzxt0sx6e52yylvy.png" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/web-technologies/internationalization?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_technologies" rel="noopener noreferrer"&gt;&lt;strong&gt;Internationalization API&lt;/strong&gt;&lt;/a&gt; shows a browser compatibility score of &lt;strong&gt;90&lt;/strong&gt;. This is a collective score out of 100 to represent browser support of a web technology. The higher this score is, the greater is the browser compatibility. The browser compatibility score is not a 100% reflection for every browser and the web technology support. However, it does give you an estimate on how much you should rely on a particular web technology in terms of browser compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this Selenium JUnit tutorial, we learned how to minimize browsers in Selenium WebDriver while performing Selenium automation testing using driver.manage.window.minimize(). We also learned about its alternatives of setting the window position or pressing the keyboard keys using the &lt;a href="https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr12_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Robot class in Selenium&lt;/a&gt;. In the end, we also implemented the same scenario across multiple browser windows of different flavors and ran them in parallel.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article and learned the different ways of minimizing the browser window.&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>java</category>
      <category>tutorial</category>
      <category>testing</category>
    </item>
    <item>
      <title>How To Handle Captcha In Selenium</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Fri, 08 Apr 2022 10:24:37 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-handle-captcha-in-selenium-55c5</link>
      <guid>https://forem.com/testmuai/how-to-handle-captcha-in-selenium-55c5</guid>
      <description>&lt;p&gt;With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them. Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; or using any other &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5oLueSYnnLRxLPYzxxzMuA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5oLueSYnnLRxLPYzxxzMuA.png" alt="[https://i.redd.it/7rvy5zqhfva41.jpg](https://i.redd.it/7rvy5zqhfva41.jpg)" width="640" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s see what Captcha is and how to automate Captcha in Selenium WebDriver. We will also read in detail about ReCAPTCHA, which is hosted by Google and protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart.&lt;/p&gt;

&lt;p&gt;Let’s deep dive into the world of Captcha and reCAPTCHA and see how to handle image Captcha in Selenium WebDriver.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Captcha?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CAPTCHA&lt;/strong&gt; stands for &lt;strong&gt;Completely Automated Public Turing Test To Tell Computers And Humans Apart&lt;/strong&gt; and is a type of challenge-response test used to ascertain whether the user is a human or a bot. The primary purpose of Captcha is to prevent bots or automated programs from using various types of computing services or collecting certain types of sensitive information such as email addresses, phone numbers, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A7lc5HnhL2SIUqfxxTKYy0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A7lc5HnhL2SIUqfxxTKYy0w.png" width="668" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image shown here is one generated by reCAPTCHA. Captchas are mostly dynamic and are intended to defeat automation frameworks like Selenium. However, since they are dynamic, they can be carried out successfully only with human interpretation and analysis, and as a result, most of the automated bots fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different test cases possible around Captcha
&lt;/h2&gt;

&lt;p&gt;Before we jump into handling Captcha scenarios in Selenium, let us first see the different test cases that are possible around Captcha. They are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To verify that the application accepts only valid Captcha.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that the Captcha code is case-sensitive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that an error message is displayed if a user enters an incorrect Captcha code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that the Captcha code on the screen is properly visible to the user or not.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that a new Captcha is getting generated on page refresh.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that a new Captcha is generated if a user enters an incorrect Captcha code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that Copy &amp;amp; Paste action doesn’t work on the Captcha input box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To verify that the application is not accepting partial Captcha code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Different ways to handle Captcha in Selenium
&lt;/h2&gt;

&lt;p&gt;Although automating Captchas in Selenium is not the best practice, automation engineers have still been trying to find ways to automate Captcha in Selenium for a very long time to achieve complete automation of their web pages.&lt;/p&gt;

&lt;p&gt;However, Captcha forms vary a lot. For example, they can be visual or drag and drop, etc. Some Captchas even use audio to support visually challenged individuals. This diverse form of Captchas makes it challenging to automate.&lt;/p&gt;

&lt;p&gt;Now that we have seen the possible test cases around Captchas, how do we efficiently handle Captcha in Selenium so that the tests run seamlessly without any hindrances? As of writing this article, the latest version of Selenium is Selenium 4. This Selenium WebDriver Tutorial for beginners and professionals will help you learn &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;what’s new in Selenium 4&lt;/a&gt; (Features and Improvements).&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mmp_FiNIYtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around Selenium testing, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;There are three ways by which we can efficiently handle Captcha in Selenium:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;By disabling Captchas in test environments&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By clicking the reCAPTCHA checkbox in Selenium&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By adding a delay in your selenium script and manually solving Captcha while running.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s understand these in a detailed manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to disable Captchas in Test Environment?
&lt;/h2&gt;

&lt;p&gt;The easiest and most foolproof way to handle captchas in Selenium is to disable the need for captchas during your test. By disabling captchas in test environments, you would no longer need to perform the Captcha task while testing a web application.&lt;/p&gt;

&lt;p&gt;The disadvantage of this approach is that you are testing something different from your production environment. Ideally, you want your automated tests to test your product in an environment that resembles your production environment.&lt;/p&gt;

&lt;p&gt;Disabling Captchas has now become very easy with Google’s open-source captcha widget called reCaptcha.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is reCAPTCHA?
&lt;/h2&gt;

&lt;p&gt;reCAPTCHA is a CAPTCHA system that enables web hosts to distinguish between human and automated access to websites. reCAPTCHA is a free service from Google and is very widely used nowadays since it supports major screen readers such as JAWS and NVDA for IE, Edge, or Chrome on Windows OS, ChromeVox for Chrome OS, and VoiceOver for Safari and Chrome on Mac OS.&lt;/p&gt;

&lt;h3&gt;
  
  
  reCAPTCHA v2
&lt;/h3&gt;

&lt;p&gt;In case you are using reCAPTCHA v2, you can put the Site Key and Secret Key also known as the test keys. These keys help in bypassing the CAPTCHA verification request and as a result, your automation case can run seamlessly.&lt;/p&gt;

&lt;p&gt;Below are the test keys for the same&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Site Key&lt;/strong&gt;: 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Secret Key&lt;/strong&gt;: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you enable the site keys you will see a warning message as shown below. This indicates that the CAPTCHA has been bypassed only for testing purposes and not in real-time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A92kktj5oFDdJYTwfabiRWg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A92kktj5oFDdJYTwfabiRWg.png" width="467" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  reCAPTCHA v3
&lt;/h3&gt;

&lt;p&gt;In the case of reCAPTCHA v3, the user needs to create their own keys for testing environments. Unlike reCAPTCHA v2, where the same keys are used for multiple environments, reCAPTCHA v3 enables the users to create separate keys for separate testing environments.&lt;/p&gt;

&lt;p&gt;It is recommended to safeguard your code and credentials so that the test credentials can never be used in production mode. This must be done in order to avoid the risk of contaminating reCAPTCHA risk analysis with the data from the test environment, which can alter the test result analysis.&lt;/p&gt;

&lt;p&gt;You can create your reCAPTCHA v3 keys from the &lt;a href="https://www.google.com/recaptcha/admin/create?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Google reCAPTCHA website&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to automate Captcha in Selenium WebDriver?
&lt;/h2&gt;

&lt;p&gt;CAPTCHAs can be automated if you are able to decode the image using OCR (Optical Character Recognition). However, to do that, you’ll need to write complex algorithms to sort out the image pattern — and writing an algorithm is not that easy. Moreover, one has to be an expert in image pattern mapping as well.&lt;/p&gt;

&lt;p&gt;But images, with time, have become progressively more unreadable, thereby reducing the chances of CAPTCHA automation.&lt;/p&gt;

&lt;p&gt;That leaves us with one way to bypass the CAPTCHA, but it won’t automate it. In that case, we can tweak the script to wait for a certain interval of time at the screen where CAPTCHA is present, and the user will enter the CAPTCHA text himself, while other fields will be filled automatically.&lt;/p&gt;

&lt;p&gt;Using this, we can achieve the target of complete web automation to a certain degree. But, this would still be a &lt;strong&gt;semi-automated&lt;/strong&gt; test. In other scenarios, where we just have a reCAPTCHA checkbox, we can simply click it using Selenium.&lt;/p&gt;

&lt;p&gt;Now we have seen how to automate Captcha in Selenium WebDriver. In the next section of this article on how to handle Captcha in Selenium, let us see both of these scenarios in our automation test.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.junit.TestCouldNotBeSkippedException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;org.junit.TestCouldNotBeSkippedException&lt;/a&gt; — This represent that a test should be skipped is not skipped. Generally, it happens when the test uses method in Assume class that it should be skipped though it is completed before processing, test got completed or other failures occurred to skip the test.&lt;/p&gt;

&lt;h2&gt;
  
  
  By clicking the reCAPTCHA checkbox in Selenium
&lt;/h2&gt;

&lt;p&gt;In case your application uses the reCAPTCHA checkbox, you will want to click the Captcha to complete the script. One of the mechanisms that reCaptcha uses is checking how long it took for the captcha to complete.&lt;/p&gt;

&lt;p&gt;Humans will take a bit longer to complete a captcha task as compared to robots. Therefore, before clicking the Captcha, you will want to add a delay (for example using WebDriverWait) to replicate human behavior.&lt;/p&gt;

&lt;p&gt;If you are wondering what is WebDriverWait in Selenium, let me share some insights on it. WebDriver equips the user with two kinds of waits in order to handle the recurring page loads, web element loads, the appearance of pop-ups and error messages, etc. on the web page. They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Implicit Wait&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explicit Wait&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;WebDriverWait falls under the category of Explicit Waits. Explicit Waits are used to halt the execution until the time a particular condition is met or the maximum time has elapsed. You will be able to understand it better once we use it in our implementation.&lt;/p&gt;

&lt;p&gt;Let us now see the automation of Captchas using an example in Selenium. In the below example, we will automate the SIGN UP page of &lt;a href="https://old.reddit.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;old.reddit.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will make use of the LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; to automate our test cases. LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that supports Selenium Grid, providing a solution to overcome every challenge you might face while performing automation testing on your local machine. &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium testing tools&lt;/a&gt; like LambdaTest offer a Selenium Grid consisting of 3000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; for you to perform Selenium automation testing effortlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch the web browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://old.reddit.com/login" rel="noopener noreferrer"&gt;https://old.reddit.com/login&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter username.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the password again in Verify Password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the email id&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait for the reCAPTCHA checkbox to appear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is the test class file which will help you to automate the checkbox. Here we have used Java with Selenium for automating Captcha in Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;If you’re a developer who’s looking to take your Java development and test engineering skills to the next level, this Selenium Java 101 certification from LambdaTest can help you reach that goal.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Java 101 certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vUxfvuAI7kE"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;strong&gt;automateCaptchaInSelenium.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class automateCaptchaInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

    [@BeforeClass](http://twitter.com/BeforeClass)
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "95.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "CaptchaInSelenium");
        capabilities.setCapability("name", "TCaptchaInSeleniumSample");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.get("[https://old.reddit.com/login](https://old.reddit.com/login)");


    }


    [@Test](http://twitter.com/Test)
    public void clickOnRecaptchaCheckBoxInSelenium() {
        try {
            System.out.println("Let's start with fresh registration");
            WebElement username=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='user']"));
            username.sendKeys("some_username_200");

            WebElement password=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='passwd']"));
            password.sendKeys("SuperStrongP@ssw0rd");

            WebElement verifyPassword=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='passwd2']"));
            verifyPassword.sendKeys("SuperStrongP@ssw0rd");

            WebElement email=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='email']"));
            email.sendKeys("[xyz@gmail.com](mailto:xyz@gmail.com)");

            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(25));
            wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(
                    By.xpath("//iframe[starts-with([@name](http://twitter.com/name), 'a-') and starts-with([@src](http://twitter.com/src), '[https://www.google.com/recaptcha'](https://www.google.com/recaptcha'))]")));

            wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath("//div[[@class](http://twitter.com/class)='recaptcha-checkbox-border']"))).click();

            System.out.println("Clicked the checkbox");

        } catch (Exception e) {

        }

    }


    [@AfterClass](http://twitter.com/AfterClass)
    public void closeBrowser() {
        driver.close();
        Reporter.log("Closing the browser", true);

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below testng.xml file for running the class file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testng.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite name="automateCaptchaInSeleniumSuite"&amp;gt;
   &amp;lt;test name="automateCaptchaInSeleniumTest"&amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="com.infa.dqcloud.testcases.profiling.automateCaptchaInSelenium"&amp;gt;

           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can check the &lt;a href="https://gist.github.com/RDayal11/1ac49b9b0f4b565d98fd4c76e061eb28?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; link here. &lt;/p&gt;

&lt;p&gt;Below is the pom.xml file you will need to install the necessary dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pom.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0)"
        xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"
        xsi:schemaLocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0) [http://maven.apache.org/xsd/maven-4.0.0.xsd](http://maven.apache.org/xsd/maven-4.0.0.xsd)"&amp;gt;
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

   &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
   &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
   &amp;lt;dependencies&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
       &amp;lt;dependency&amp;gt;
           &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
           &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
           &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
       &amp;lt;/dependency&amp;gt;
   &amp;lt;/dependencies&amp;gt;

   &amp;lt;properties&amp;gt;
       &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
       &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
   &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us now understand the different areas of code in detail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Imported Dependencies:&lt;/strong&gt; Here, we have imported all the necessary classes of Selenium WebDriver, WebDriverWait, Desired Capabilities, and RemoteWebDriver to set the respective browser capabilities and run the test cases on the grid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2264%2F1%2AA3ABsADoPSlucx17CPS5_A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2264%2F1%2AA3ABsADoPSlucx17CPS5_A.png" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Variables:&lt;/strong&gt; As we have used a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Grid Cloud&lt;/a&gt; like LambdaTest to perform our test execution, we are using the below-shown variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetb0g9psft13cbkrwjn3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetb0g9psft13cbkrwjn3.png" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;@BeforeClass(Setup Method):&lt;/strong&gt; Here, we have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Remote WebDriver&lt;/a&gt;. After that, we are opening the website in the launched browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2264%2F1%2Awxdfk90TPL5zSCW767oPBw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2264%2F1%2Awxdfk90TPL5zSCW767oPBw.png" width="800" height="866"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@ Test(clickOnRecaptchaCheckBoxInSelenium):&lt;/strong&gt; In this case, we are locating the web elements for &lt;strong&gt;username&lt;/strong&gt; and then entering the username value into it. Similarly, we are locating the corresponding web elements for the &lt;strong&gt;password&lt;/strong&gt;, &lt;strong&gt;verify password&lt;/strong&gt;, and email text boxes as shown in the below image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQQ7ZQ7dCJnj3JRsPJMLGFQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AQQ7ZQ7dCJnj3JRsPJMLGFQ.png" width="698" height="667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are making use of &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;XPaths in Selenium&lt;/a&gt; for locating each element. So, in order to locate the element and write its XPath, you can simply right-click on the web element and click on Inspect. Then, in the Elements tab, you can start writing the locator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3152%2F1%2AtGVc4YE7jKmdD7KnZpGADA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3152%2F1%2AtGVc4YE7jKmdD7KnZpGADA.png" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once all the above elements have been located and their values are entered, we wait for the frame having the reCAPTCHA checkbox to be visible and switch to it. We achieve this by making use of WebDriverWait class and ExpectedConditions. &lt;a href="https://www.lambdatest.com/blog/expected-conditions-in-selenium-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;ExpectedConditions in Selenium&lt;/a&gt; lets you wait for the occurrence of a specified condition before execution can proceed to the next step. If the condition is not met within the expected time duration, an appropriate exception is raised.&lt;/p&gt;

&lt;p&gt;Finally, when we have switched to the frame, we wait for the checkbox to be clickable and finally click on it. In case you are new to iFrames, you can check out the blog on &lt;a href="https://www.lambdatest.com/blog/handling-frames-and-iframes-selenium-c-sharp/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;handling iFrames in Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2836%2F1%2Ao3D8J03IopEFeX6Mcqq71Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2836%2F1%2Ao3D8J03IopEFeX6Mcqq71Q.png" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AJcR8FjKRls7ZqhH8QDAZfA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AJcR8FjKRls7ZqhH8QDAZfA.png" width="655" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@AfterTest(closeBrowser):&lt;/strong&gt; In this method, we are closing the browser that we had launched. Once the tests are completed, you can view the test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/dashboard?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AIBean2s2q-6i8k6ylmG24Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AIBean2s2q-6i8k6ylmG24Q.png" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We saw how to click the reCAPTCHA checkbox in Selenium; however, if you are using Puppeteer or &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, you can open an URL containing the captcha and find the specific captcha DOM element, and click the Captcha.&lt;/p&gt;

&lt;p&gt;In order to see the Test Overview, you can navigate to the &lt;a href="https://analytics.lambdatest.com/test-overview?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The Test Overview showcases the Test Case Health Snapshot for tests that consistently pass, consistently fail, etc. Test Summary, on the other hand, displays the total number of tests passed, failed, completed, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2Aqs3UWkqvSpPWcoCH_-SFeQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2Aqs3UWkqvSpPWcoCH_-SFeQ.png" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.junit.runners.model.TestTimedOutException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;org.junit.runners.model.TestTimedOutException&lt;/a&gt; — This happens when test is not able complete within the specified time in junit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solving Captcha issues in Selenium
&lt;/h2&gt;

&lt;p&gt;With this approach, your test will detect the Captcha and wait for a specific amount of time, allowing you to enter the correct captcha answer. While waiting for the captcha answer, you will need to manually look at the captcha question, solve the captcha and pass the answer to the (automated) test.&lt;/p&gt;

&lt;p&gt;However, this option to handle Captcha in Selenium is not recommended, as it requires manual intervention during an automated test, and as a result, the test case is not 100% automated.&lt;/p&gt;

&lt;p&gt;We can achieve it again by using &lt;a href="https://www.lambdatest.com/blog/selenium-wait-for-page-to-load/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;WebDriverWait in Selenium&lt;/a&gt; and giving the user the time to solve the captcha manually. WebDriver will wait till the next action is ready.&lt;/p&gt;

&lt;p&gt;We can see the same Use Case where once the reCAPTCHA checkbox has been clicked, we wait till the SIGN UP button gets enabled, and by the time the user gets the opportunity to solve the Captcha manually.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AuSWKS443CmwLswuKPlEiXg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AuSWKS443CmwLswuKPlEiXg.png" width="786" height="864"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file you can use to automate the scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;automateCaptchaInSelenium.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class automateCaptchaInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

    [@BeforeClass](http://twitter.com/BeforeClass)
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "95.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "CaptchaInSelenium");
        capabilities.setCapability("name", "TCaptchaInSeleniumSample");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.get("[https://old.reddit.com/login](https://old.reddit.com/login)");


    }

    [@Test](http://twitter.com/Test)
    public void manuallySolveCaptchaWithDelayInSelenium() {
        try {
            System.out.println("Let's start with fresh registration");
            WebElement username=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='user']"));
            username.sendKeys("some_username_200");

            WebElement password=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='passwd']"));
            password.sendKeys("SuperStrongP@ssw0rd");

            WebElement verifyPassword=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='passwd2']"));
            verifyPassword.sendKeys("SuperStrongP@ssw0rd");

            WebElement email=driver.findElement(By.xpath("//input[[@name](http://twitter.com/name)='email']"));
            email.sendKeys("[xyz@gmail.com](mailto:xyz@gmail.com)");

            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(25));
            wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(
                    By.xpath("//iframe[starts-with([@name](http://twitter.com/name), 'a-') and starts-with([@src](http://twitter.com/src), '[https://www.google.com/recaptcha'](https://www.google.com/recaptcha'))]")));

             wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath("//div[[@class](http://twitter.com/class)='recaptcha-checkbox-border']"))).click();

            System.out.println("Clicked the checkbox");

            wait.until(ExpectedConditions.elementToBeClickable(
                    By.xpath("//button[text()='sign up']"))).click();

            System.out.println("Clicked the sign up button");

        } catch (Exception e) {

        }

    }


    [@AfterClass](http://twitter.com/AfterClass)
    public void closeBrowser() {
        driver.close();
        Reporter.log("Closing the browser", true);

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below testng.xml file for running the class file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testng.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite name="automateCaptchaInSeleniumSuite"&amp;gt;
   &amp;lt;test name="automateCaptchaInSeleniumTest"&amp;gt;
       &amp;lt;classes&amp;gt;
           &amp;lt;class name="com.infa.dqcloud.testcases.profiling.automateCaptchaInSelenium"&amp;gt;

           &amp;lt;/class&amp;gt;
       &amp;lt;/classes&amp;gt;
   &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, everything remains the same as explained in the code walkthrough of our first example except the part where we wait for the SIGN UP button to be clickable after the checkbox has been clicked. Now, after the reCAPTCHA checkbox has been clicked, the screen selects the applicable images. Once that is done, the SIGN UP button gets clickable. Hence, when the user manually solves the captcha, the web driver waits for the SIGN UP button to get clickable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AfHURsHIu11nz9iK72qRDww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AfHURsHIu11nz9iK72qRDww.png" width="800" height="258"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to handle invisible reCaptcha in Selenium?
&lt;/h2&gt;

&lt;p&gt;reCAPTCHA v2 offers an invisible captcha, which does not require the user to perform any interaction with the captcha. Unfortunately, the invisible captcha tries to block the web traffic that appears to come from a bot, so in order to avoid this, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change the user-agent of your test script.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to change the user agent?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;For Chrome&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case you are using the Chrome browser follow the below steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, you should add a User-Agent Switcher to your Chrome browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, go to &lt;a href="https://chrome.google.com/webstore/detail/user-agent-switcher-for-c/djflhoibgkdhkhhcedjiklpkjnoahfmg?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;User-Agent Switcher&lt;/a&gt; settings at Chrome extensions section and get the desired agent’s information.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A1MqvCdqTWN5kE5rvUjiYNA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A1MqvCdqTWN5kE5rvUjiYNA.png" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Later, in your test script, you can make use of the ChromeOptions class and add the corresponding arguments as shown below in the Before Setup Method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36");
driver = new ChromeDriver(options);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;For Firefox&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case you are using the Firefox browser follow the below steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, you should add &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;User-Agent Switcher&lt;/a&gt; to your Firefox browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save all device lists to the desktop and import them as shown below.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMtWC0VjelMJ6-2KXIQBTGw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMtWC0VjelMJ6-2KXIQBTGw.png" width="542" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Go to Tools-&amp;gt; Default User Agent -&amp;gt; Edit User Agents&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A-wKRBMHL7ZNtjhoA_WgZAA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A-wKRBMHL7ZNtjhoA_WgZAA.png" width="395" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Then select Mobile Devices -&amp;gt; Devices -&amp;gt; HTC -&amp;gt; One M9 — Android 6.0 -Chrome 52.0 and then click Edit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2Fz7ztvDqscx0Z44YZDCMw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2Fz7ztvDqscx0Z44YZDCMw.png" width="542" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, you can see the user agent value of the HTC One M9 as shown below. Copy and save these values for user agent manipulation in our selenium web driver test automation code.&lt;/p&gt;

&lt;p&gt;Later you can use the setPreference method in your BeforeSetup method with the general.useragent.override flag and pass the value you had collected in the previous step.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FirefoxProfile profile = new FirefoxProfile();
//Change User Agent to HTC ONE M9
profile.setPreference("general.useragent.override", "Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36");
driver = new FirefoxDriver(profile);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;These were some of the ways of handling invisible reCAPTCHAs in Firefox and Chrome browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We know that automating Captchas in Selenium is not one of the best practices. However, we might need to replicate our actual use case. In this article on how to handle Captcha in Selenium, we read what are Captchas and how we can deal with them in Selenium automation testing. We also read about reCAPCTHAs and how to disable them in testing environments, followed by how to automate Captcha in Selenium WebDriver. Run your &lt;a href="https://www.lambdatest.com/webdriverio-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr08_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;WebdriverIO tests&lt;/a&gt; &amp;amp; start your free testing. In the end, we also saw what Invisible Captchas are and how to handle them.&lt;/p&gt;

&lt;p&gt;I hope you learned something new about Captchas in Selenium and enjoyed reading this blog.&lt;br&gt;
Happy Testing!!&lt;/p&gt;

</description>
      <category>java</category>
      <category>testing</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>FindElement And FindElements In Selenium [Differences]</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Thu, 07 Apr 2022 15:04:41 +0000</pubDate>
      <link>https://forem.com/testmuai/findelement-and-findelements-in-selenium-differences-58b5</link>
      <guid>https://forem.com/testmuai/findelement-and-findelements-in-selenium-differences-58b5</guid>
      <description>&lt;p&gt;Finding an element in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; can be both interesting and complicated at the same time. If you are not using the correct method for locating an element, it could sometimes be a nightmare. For example, if you have a web element with both ID and Text attributes, ID remains constantly changing, whereas Text remains the same. Using an &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;ID locator to locate web elements&lt;/a&gt; can impact all your test cases, and imagine the regression results over a few builds in such cases. This is where the methods findElement and findElements in Selenium can help.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AlxRkHHEt-GUE01RTokqbSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AlxRkHHEt-GUE01RTokqbSQ.png" alt="[https://giphy.com/gifs/season-9-the-simpsons-9x17-xT5LMulm0nOD5KpRNm](https://giphy.com/gifs/season-9-the-simpsons-9x17-xT5LMulm0nOD5KpRNm)" width="262" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The findElement method in Selenium can help you enormously while using &lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; for finding web elements while performing Selenium automation testing. Let’s see the different implements of findElement in Selenium and the differences between findElement and findElements in Selenium.&lt;/p&gt;

&lt;p&gt;Let’s get started!!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find an Element in Selenium?
&lt;/h2&gt;

&lt;p&gt;When you start to &lt;a href="https://www.lambdatest.com/blog/how-to-write-test-scripts-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;write your Selenium automation script&lt;/a&gt;, interaction with web elements becomes your first vital step because it’s the web elements you play around with within your test script. However, interaction with these web elements can only happen if you identify them using the right approach.&lt;/p&gt;

&lt;p&gt;findElement method in Selenium is a command which helps you identify a web element. There are multiple ways that findElement provides to uniquely identify a web element within the web page using &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;web locators in Selenium&lt;/a&gt; like ID, Name, Class Name, Link Text, Partial Link Text, Tag, which we will see later in the blog.&lt;/p&gt;

&lt;p&gt;For now, let’s see the syntax of using findElement in Selenium. We would be using Selenium with Java for the implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax to find an Element in Selenium
&lt;/h2&gt;

&lt;p&gt;The syntax to find an Element in Selenium is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.&amp;lt;LocatorStrategy&amp;gt;("LocatorValue"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As shown in the above syntax, this command accepts the “By” object as the argument and returns a WebElement object. The “By” is a locator or query object and accepts the locator strategy. The Locator Strategy can assume the below values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tag Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XPath&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Selector&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if you want to use ID as the Locator Strategy to identify any web element, it would look like below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement ele1 = driver.findElement(By.id(“id”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Locator Strategy further accepts the Locator Value to identify a web element uniquely.&lt;/p&gt;

&lt;p&gt;If there is no matching element within the web page, findElement throws NoSuchElementException.&lt;/p&gt;

&lt;p&gt;Let us understand it using an example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LambdaTest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try to find a web element that is not present on the screen.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AWIZVr4GcnD3keVwhDQ2qlg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AWIZVr4GcnD3keVwhDQ2qlg.png" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that supports Selenium Grid, providing a solution to every obstacle you face while performing Selenium automation testing using your local machine. Selenium testing tools like LambdaTest offer an online Selenium Grid consisting of 3000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; for you to perform Selenium automation testing effortlessly.&lt;/p&gt;

&lt;p&gt;Refer to the below test case for the above scenario:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3192%2F1%2AjRgkH1aSAQ6ESIkbC6kc2Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3192%2F1%2AjRgkH1aSAQ6ESIkbC6kc2Q.png" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above test case, the checkbox web element is not present on the Selenium Playground main home page, and hence, it will throw NoSuchElementException. Check out the console output in this case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AEAzElrnwhCpq8_uw1ybylg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AEAzElrnwhCpq8_uw1ybylg.png" width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you must be wondering, what if the locator value returns multiple matching elements? FindElement would return you the first element within the web page which matches the locator value. The next question arises: What if you need all those matching web elements? This is where findElements in Selenium comes into the picture.&lt;/p&gt;

&lt;p&gt;Let’s see what findElements has to offer!!&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.junit.rules.ExpectedException?utm_source=linkedin&amp;amp;utm_medium=group&amp;amp;utm_campaign=apr07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;org.junit.rules.ExpectedException&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ExpectedException is a rule which helps scripts to verify that the script throws the specific exception or not&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find Elements in Selenium?
&lt;/h2&gt;

&lt;p&gt;findElements in Selenium returns you the list of web elements that match the locator value, unlike findElement, which returns only a single web element. If there are no matching elements within the web page, findElements returns an empty list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax to find Elements in Selenium
&lt;/h2&gt;

&lt;p&gt;The syntax to find Elements in Selenium is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; elementName = driver.findElements(By.&amp;lt;LocatorStrategy&amp;gt;("LocatorValue"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;findElements in Selenium example: If you want to use ID as the Locator Strategy for identifying a list of web elements, it would look something like below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; ele1 = driver.findElements(By.id(“id”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Similar to the findElement() command, this method also accepts the “By” object as the parameter and returns a list of web elements.&lt;/p&gt;

&lt;p&gt;Now, since we have seen findElement and findElements in Selenium example, let’s understand the difference between the findElement and findElements in Selenium Java.&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference between findElement and findElements in Selenium Java
&lt;/h2&gt;

&lt;p&gt;Now that we read about findElement and findElements, let’s have a quick look at their major differences.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;findElement&lt;/th&gt;
&lt;th&gt;findElements&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Returns the first matching web element within the web page even if multiple web elements match the locator value.&lt;/td&gt;
&lt;td&gt;Returns a list of multiple web elements matching the locator value.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Throws NoSuchElementException in case there are no matching elements.&lt;/td&gt;
&lt;td&gt;Returns an empty list in case there are no matching elements.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Returns a single web element&lt;/td&gt;
&lt;td&gt;Returns a collection of web elements.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No indexing is required since only one element is returned.&lt;/td&gt;
&lt;td&gt;Each web element is indexed starting from 0.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Note: The latest version of Selenium is Selenium 4 when writing this article. This Selenium WebDriver Tutorial for beginners and professionals will help you learn &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;what’s new in Selenium 4&lt;/a&gt; (Features and Improvements).&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mmp_FiNIYtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/what-is-continuous-integration-and-continuous-delivery/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;CI/CD&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Locator Strategies of findElement and findElements in Selenium Java
&lt;/h2&gt;

&lt;p&gt;Let us now understand the various locator strategies that can be used with findElement and findElements in Selenium Java. We will see their implementation making use of &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LambdaTest.&lt;/p&gt;

&lt;p&gt;We will also make use of the LambdaTest &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt; to automate our test cases.&lt;/p&gt;

&lt;p&gt;Selenium Grid refers to a software testing setup that enables QAs to perform parallel tests across multiple browsers and devices with unique operating systems. When the entire setup of Selenium Grid is accessible using cloud-based servers, it is called Selenium Grid On Cloud. An online Selenium Grid helps you focus on &lt;a href="https://www.lambdatest.com/blog/27-best-practices-selenium-test-automation/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;writing better Selenium test&lt;/a&gt; scripts rather than worrying about infrastructure maintenance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by ID
&lt;/h2&gt;

&lt;p&gt;As we all know, the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;ID locator in Selenium&lt;/a&gt; is one of the widely used locators for locating desired WebElement on a document (or page). If a website uses dynamically generated IDs, this strategy cannot uniquely find an element. However, it will still return the first web element which matches the locator value.&lt;/p&gt;

&lt;p&gt;For example, If you have a web element with a tag as Button which has a dynamic ID, where ID is getting changed from ‘ID-3465-text1’ to ‘ID-4434-textE2’, in such cases, it becomes difficult to use the ID attribute. However, if it remains static, you can easily use the ID to locate the Web Element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by ID:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName = driver.findElement(By.id(“id value”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the &lt;a href="https://www.lambdatest.com/selenium-playground/checkbox-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;checkbox demo page&lt;/a&gt; of Selenium Playground and locate the checkbox web element using ID. Further, we will click on the same checkbox and validate the success message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2168%2F1%2AhWEEt-YASk3Mzn_FvFpAFg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2168%2F1%2AhWEEt-YASk3Mzn_FvFpAFg.png" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of id in the above case would be&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement checkBox = driver.findElement(By.id(“isAgeSelected”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider the below test case file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class AutomationUsingFindElement {

    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeTest
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }



    @Test
    public void findElementById() {
        try {
            System.out.println("Logging into Lambda Test Checkbox Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");

            WebElement checkBox= driver.findElement(By.id("isAgeSelected"));
            checkBox.click();
            System.out.println("Clicked on the Checkbox");

            WebElement successMessage=driver.findElement(By.id("txtAge"));
            String expectedMessage=successMessage.getText();

            Assert.assertEquals("Success - Check box is checked", expectedMessage);
        } catch (Exception e) {

        }

    }

    @AfterTest
    public void closeBrowser() {
        driver.close();
        System.out.println("The driver has been closed.");

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below testng.xml file for running the test case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&amp;gt;
&amp;lt;suite  name="AutomationUsingFindElementSuite"&amp;gt;

    &amp;lt;test name="AutomationUsingFindElementTest" &amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name="LambdaTest.AutomationUsingFindElement" &amp;gt;
            &amp;lt;/class&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below pom.xml file for installing the necessary dependencies.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;

    &amp;lt;properties&amp;gt;
        &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
        &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
    &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us now understand the different areas of code in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Imported Dependencies&lt;/strong&gt;: Here, we have imported all the necessary classes of Selenium WebDriver, WebDriverWait, Desired Capabilities, and RemoteWebDriver to set the respective browser capabilities and run the test cases on the grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2960%2F1%2AU5Kn15bxBB6AV7i35CQilQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2960%2F1%2AU5Kn15bxBB6AV7i35CQilQ.png" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: As we have used a &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Grid Cloud&lt;/a&gt; like LamdaTest to perform our test execution, we are using the below-shown variables.&lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2304%2F1%2ARiq8MQmVuvczODVgOqetlQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2304%2F1%2ARiq8MQmVuvczODVgOqetlQ.png" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have also used the Listener class here in order to customize the &lt;a href="https://www.lambdatest.com/blog/how-to-use-testng-reporter-log-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;TestNG Report&lt;/a&gt;. TestNG provides us with a lot of &lt;a href="https://www.lambdatest.com/blog/testng-listeners-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;TestNG Listeners&lt;/a&gt; (e.g. IAnnotationTransformer, IReporter, etc). These interfaces are used while performing &lt;a href="https://www.lambdatest.com/selenium-cloud-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium cloud testing&lt;/a&gt; mainly to generate logs and customize the TestNG reports.&lt;/p&gt;

&lt;p&gt;To implement the Listener class, you can simply add an annotation in your test class just above your class name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@Listeners](http://twitter.com/Listeners)(PackageName.ClassName.class)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3232%2F1%2ApfvoRIvzyZlyo9KNcQcfEg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3232%2F1%2ApfvoRIvzyZlyo9KNcQcfEg.png" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. @ BeforeTest(Setup Method):&lt;/strong&gt; Here, we have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Selenium Remote WebDriver&lt;/a&gt;. After that, we are opening the website in the launched browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3708%2F1%2AHd7tYZ4nu-gvpcfuak45Rg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3708%2F1%2AHd7tYZ4nu-gvpcfuak45Rg.png" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@ Test(findElementById)&lt;/strong&gt;: In this case, we first locate the web element for the checkbox using ID and then click on it. Later, we locate the success message and validate if it appears correctly after clicking on the checkbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;@ AfterTest(closeBrowser):&lt;/strong&gt; Here, we are just closing the launched browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3208%2F1%2APdgDRQqDQylRRt-maibGcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3208%2F1%2APdgDRQqDQylRRt-maibGcw.png" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can also view your test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3344%2F1%2AKd6MtZlbHk0B41-PX781MA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3344%2F1%2AKd6MtZlbHk0B41-PX781MA.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by Name
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/how-to-use-name-locator-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Name locator in Selenium&lt;/a&gt; is similar to find by ID, except the driver will locate an element by the “name” attribute instead of “id”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by Name:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName = driver.findElement(By.name(“name”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the &lt;a href="https://www.lambdatest.com/selenium-playground/input-form-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;input form page&lt;/a&gt; of Selenium Playground and write the locator for the input text boxes such as Name, Email, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2434%2F1%2AB09TX4JjHg3bbT9lttLrOA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2434%2F1%2AB09TX4JjHg3bbT9lttLrOA.png" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of name in the above case would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement emailTextBox= driver.findElement(By.name(“email”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let us automate entering the value of name and email making use of the findElement by Name.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class AutomationUsingFindElement {

    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeTest
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }


    @Test
    public void findElementByName() {
        try {
            System.out.println("Logging into Lambda Test Input Form Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/input-form-demo");

            WebElement nameTextBox = driver.findElement(By.name("name"));
            nameTextBox.sendKeys("LambdaTest");
            System.out.println("Entered Name");

            WebElement emailTextBox = driver.findElement(By.name("email"));
            emailTextBox.sendKeys("lambdatest@gmail.com");
            System.out.println("Entered Email");

        } catch (Exception e) {

        }

    }

    @AfterTest
    public void closeBrowser() {
        driver.close();
        System.out.println("The driver has been closed.");

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@ Test(findElementByName): In this case, we are first locating the web element for the Name text box and entering a value in the same. Later, we are locating the web element for the Email text box and the entering value in the email text box.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by ClassName
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/selenium-java-tutorial-class-name-locator-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;ClassName locator in Selenium&lt;/a&gt; finds the elements on the web page based on the CLASS attribute value. Here the value of the “class” attribute is passed as the locator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by ClassName:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName = driver.findElement(By.classname(“className”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the &lt;a href="https://www.lambdatest.com/selenium-playground/table-pagination-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;table pagination demo&lt;/a&gt; page of Selenium Playground and write the locator for the dropdown to change the number of rows being displayed to 10.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2Aq7D-MTYajZYGYEvFvBUqCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2Aq7D-MTYajZYGYEvFvBUqCg.png" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of ClassName in the above case would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement selectDropdown=driver.findElement(By.className(“form-control”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file that can be used for implementing the test case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class automateCaptchaInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeClass
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");

        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        Reporter.log("Logging into Selenium Playground", true);

    }

    @Test
    public void findElementByClassName() {
        try {
            System.out.println("Logging into Lambda Test Table Pagination Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/table-pagination-demo");

            WebElement selectDropdown=driver.findElement(By.className("form-control"));
            Select select = new Select(selectDropdown);
            select.selectByVisibleText("10");

            System.out.println("Changed the pagination dropdown to 10");
        } catch (Exception e) {

        }

    }


    @AfterClass
    public void closeBrowser() {
        driver.close();
        Reporter.log("Closing the browser", true);

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@ Test(findElementByClassName)&lt;/strong&gt;: In this case, we are first locating the web element for the dropdown using ClassName. Later, we are using Select Class for changing the dropdown value to 10 by using the selectByVisibleText option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3176%2F1%2A_ydRhK096TZSh26e-BXPKw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3176%2F1%2A_ydRhK096TZSh26e-BXPKw.png" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.junit.runner.FilterFactory.FilterNotCreatedException?utm_source=linkedin&amp;amp;utm_medium=group&amp;amp;utm_campaign=apr07_kj&amp;amp;utm_term=kj&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;org.junit.runner.FilterFactory.FilterNotCreatedException&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It happens when junit filters can’t be created&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by TagName
&lt;/h2&gt;

&lt;p&gt;A tagName is a part of a DOM structure where every element on a page is defined via tags like input tag, button tag or anchor tag, etc. Each tag has multiple attributes like ID, name, value class, etc. The &lt;a href="https://www.lambdatest.com/blog/locating-elements-by-tagname-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;TagName locator in Selenium&lt;/a&gt; finds the elements on the web page based on the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by TagName:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName = driver.findElement(By.tagName(“tagname”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the same &lt;a href="https://www.lambdatest.com/selenium-playground/table-pagination-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;table pagination demo&lt;/a&gt; page of Selenium Playground and write the locator for the dropdown to change the number of rows displayed using the tag name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2520%2F1%2AHvYYaqJN6buQ6VcPqW5Clw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2520%2F1%2AHvYYaqJN6buQ6VcPqW5Clw.png" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of tag name in the above case would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName = driver.findElement(By.tagName(“select”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file that can be used for implementing the test case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class automateCaptchaInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeClass
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");

        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        Reporter.log("Logging into Selenium Playground", true);

    }

    @Test
    public void findElementByTagName() {
        try {
            System.out.println("Logging into Lambda Test Table Pagination Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/table-pagination-demo");

            WebElement selectDropdown=driver.findElement(By.tagName("select"));
            Select select = new Select(selectDropdown);
            select.selectByVisibleText("10");

            System.out.println("Changed the pagination dropdown to 10");
        } catch (Exception e) {

        }

    }


    @AfterClass
    public void closeBrowser() {
        driver.close();
        Reporter.log("Closing the browser", true);

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@ Test(findElementByTagName): In this case, we are first locating the web element for the dropdown using TagName. Later, we are using Select Class for changing the dropdown value to 10 by using the selectByVisibleText option.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by Link Text
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/using-link-text-and-partial-link-text-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;Link Text locator in Selenium&lt;/a&gt; is used to identify the hyperlinks on a web page. It is determined with the help of an anchor tag. For creating the hyperlinks on a web page, we can use an anchor tag followed by the link Text.&lt;/p&gt;

&lt;p&gt;Accessing links using their exact link text is done through the findElement by Link Text method. However, if two links have the exact link text, this method will only access the first one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by Link Text:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.linkText(“link text”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the &lt;a href="https://www.lambdatest.com/selenium-playground/radiobutton-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;radio button demo&lt;/a&gt; page of Selenium Playground and write the locator for the Selenium Playground hyperlink, which is used for navigation to the home page as highlighted below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2582%2F1%2AaJWCQSmuV59jCl6qu1ZrAg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2582%2F1%2AaJWCQSmuV59jCl6qu1ZrAg.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of link text in the above case would be&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement seleniumPlaygroundLink= driver.findElement(By.linkText(“Selenium Playground”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file which can be used for implementing the case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class AutomationUsingFindElement {

    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeTest
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    @Test
    public void findElementByLinkText() {
        try {
            System.out.println("Logging into Lambda Test Radio Button Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/radiobutton-demo");

            WebElement seleniumPlaygroundLink= driver.findElement(By.linkText("Selenium Playground"));
            seleniumPlaygroundLink.click();
            System.out.println("Clicked on the Selenium Playground Navigation Link");


        } catch (Exception e) {

        }

    }


    @AfterTest
    public void closeBrowser() {
        driver.close();
        System.out.println("The driver has been closed.");

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@ Test(findElementByLinkText): In this case, we are first locating the web element for the navigation link to the main Selenium Playground page using Link Text and later, click on the same.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by Partial Link Text
&lt;/h2&gt;

&lt;p&gt;Accessing links using a portion of their link text is done using the By.partialLinkText() method. If you specify a partial link text that has multiple matches, only the first match will be accessed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by Partial Link Test:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.partialLinkText(“partial link text”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the same &lt;a href="https://www.lambdatest.com/selenium-playground/radiobutton-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;radio button demo&lt;/a&gt; page of Selenium Playground and write the locator for the Selenium Playground hyperlink, which is used for navigating to the home page as highlighted below. However, this time we will make use of the partial link text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2582%2F1%2AaJWCQSmuV59jCl6qu1ZrAg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2582%2F1%2AaJWCQSmuV59jCl6qu1ZrAg.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of link text in the above case would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement seleniumPlaygroundLink= driver.findElement(By.partialLinkText(“Playground”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file which can be used for implementing the case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class AutomationUsingFindElement {

    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeTest
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }


    @Test
    public void findElementByPartialLinkText() {
        try {
            System.out.println("Logging into Lambda Test Radio Button Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/radiobutton-demo");

            WebElement seleniumPlaygroundLink= driver.findElement(By.partialLinkText("Playground"));
            seleniumPlaygroundLink.click();
            System.out.println("Clicked on the Selenium Playground Navigation Link");
        } catch (Exception e) {

        }

    }

    @AfterTest
    public void closeBrowser() {
        driver.close();
        System.out.println("The driver has been closed.");

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@ Test(findElementByPartialLinkText):&lt;/strong&gt; In this case, we are first locating the web element for the navigation link to the main Selenium Playground page using Partial Link Text and later, click on the same.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/VeV_sup5S8E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by CSS Selector
&lt;/h2&gt;

&lt;p&gt;CSS Selectors are one of the locator strategies used in Selenium to identify the web elements. The &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;CSS Selectors locator in Selenium&lt;/a&gt; mainly uses the character sequence pattern, which identifies the web elements based on their HTML structure. Locating an element using a CSS selector in Selenium may seem a little more difficult than using attributes like id, name, link, etc. Still, it’s one of the most efficient strategies to locate dynamic elements that don’t have consistent HTML attributes. CSS Selector syntax is quite similar to the XPath syntax. It can be represented as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Node[attribute name=”attribute value”]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let us now see the syntax of using a CSS selector with the findElement in Selenium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Element by CSS Selector:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.cssSelector(“css selector”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the single &lt;a href="https://www.lambdatest.com/selenium-playground/checkbox-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;checkbox demo page&lt;/a&gt; of Selenium Playground and write the CSS selector for the checkbox, and later use the same in locating the web element using findElement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AuymH8qbbhBBFBpIWT3Cvfg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AuymH8qbbhBBFBpIWT3Cvfg.png" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of CSS selector in the above case would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement checkbox= driver.findElement(By.cssSelector(“input[id='isAgeSelected']”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file which can be used for implementing the case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.Select;
import java.net.MalformedURLException;
import java.net.URL;

@Listeners({util.Listener.class})
class AutomationUsingFindElement {

    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "@hub.lambdatest.com/wd/hub";

    @BeforeTest
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "AutomationUsingFindElement");
        capabilities.setCapability("name", "AutomationUsingFindElementSuite");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }



    @Test
    public void findElementByCSSSelector() {
        try {
            System.out.println("Logging into Lambda Test Checkbox Demo Page");
            driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");

            WebElement checkbox= driver.findElement(By.cssSelector("input[id='isAgeSelected']"));
            checkbox.click();
            System.out.println("Clicked on the Single Checkbox button");

            WebElement successMessage=driver.findElement(By.id("txtAge"));
            String expectedMessage=successMessage.getText();

            Assert.assertEquals("Success - Check box is checked", expectedMessage);
        } catch (Exception e) {

        }

    }



    @AfterTest
    public void closeBrowser() {
        driver.close();
        System.out.println("The driver has been closed.");

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@ Test(findElementByCSSSelector)&lt;/strong&gt;: In this case, we are first locating the web element for the checkbox using CSS selector and then clicking on it. Later, we locate the success message and validate if it appears correctly after clicking on the checkbox.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by XPath
&lt;/h2&gt;

&lt;p&gt;Also known as XML Path, the &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;XPath locator in Selenium&lt;/a&gt; is one of the most commonly used &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;locators in Selenium WebDriver&lt;/a&gt; that can help you navigate through the HTML structure of a page.&lt;/p&gt;

&lt;p&gt;The basic format of XPath in Selenium is explained below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;XPath = //tagname[[@Attribute](http://twitter.com/Attribute)=’Value’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let us now see the syntax of using XPaths with find elements in Selenium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax to find Elements by XPath:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.xpath(“xpath”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Use Case to find Element by XPath:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see the same example as we saw in the CSS selector, single &lt;a href="https://www.lambdatest.com/selenium-playground/checkbox-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;checkbox demo page&lt;/a&gt; of Selenium Playground, and write the XPath for the checkbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F1%2AQGa44zYDjoAdNwY6qKNRwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2076%2F1%2AQGa44zYDjoAdNwY6qKNRwg.png" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The correct locator value making use of XPath in the above case would be&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement checkbox= driver.findElement(By.xpath(“//input[[@id](http://twitter.com/id)='isAgeSelected']”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file which can be used for implementing the case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

    import io.github.bonigarcia.wdm.WebDriverManager;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;
    import org.openqa.selenium.support.ui.Select;
    import java.net.MalformedURLException;
    import java.net.URL;

    @Listeners({util.Listener.class})
    class AutomationUsingFindElement {

        public String username = "YOUR USERNAME";
        public String accesskey = "YOUR ACCESSKEY";
        public static RemoteWebDriver driver = null;
        public String gridURL = "@hub.lambdatest.com/wd/hub";

        @BeforeTest
        public void setUp() throws Exception {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("browserName", "chrome");
            capabilities.setCapability("version", "96.0");
            capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
            capabilities.setCapability("build", "AutomationUsingFindElement");
            capabilities.setCapability("name", "AutomationUsingFindElementSuite");
            try {
                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
            } catch (MalformedURLException e) {
                System.out.println("Invalid grid URL");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }


        @Test
        public void findElementByXPath() {
            try {
                System.out.println("Logging into Lambda Test Checkbox Demo Page");
                driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");

                WebElement checkbox= driver.findElement(By.xpath("//input[@id='isAgeSelected']"));
                checkbox.click();
                System.out.println("Clicked on the Single Checkbox button");

                WebElement successMessage=driver.findElement(By.id("txtAge"));
                String expectedMessage=successMessage.getText();

                Assert.assertEquals("Success - Check box is checked", expectedMessage);
            } catch (Exception e) {

            }

        }

        @AfterTest
        public void closeBrowser() {
            driver.close();
            System.out.println("The driver has been closed.");

        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@ Test(findElementByCSSSelector): In this case, we are first locating the web element for the checkbox using XPath and then clicking on it. Later, we locate the success message and validate if it appears correctly after clicking on the checkbox.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case to find Elements by XPath:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see an implementation using findElements as well.&lt;/p&gt;

&lt;p&gt;Log in to Selenium Playground and list down all the section headers on the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3166%2F1%2A5Lf1VNPlpmqPsXhBpNONyQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3166%2F1%2A5Lf1VNPlpmqPsXhBpNONyQ.png" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Locator:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we inspect the section headers using XPath, we see that multiple elements are being returned making use of the same XPath. Hence, in such cases, it would be appropriate to use findElements.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; sectionHeaders= driver.findElements(By.xpath(“//h2[[@class](http://twitter.com/class)='st_heading']”));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2744%2F1%2AMSkJNptFWzq7K1BolmH7iw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2744%2F1%2AMSkJNptFWzq7K1BolmH7iw.png" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the test class file which can be used for implementing the case.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

    import io.github.bonigarcia.wdm.WebDriverManager;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.List;

    @Listeners({util.Listener.class})
    class AutomationUsingFindElement {

        public String username = "YOUR USERNAME";
        public String accesskey = "YOUR ACCESSKEY";
        public static RemoteWebDriver driver = null;
        public String gridURL = "@hub.lambdatest.com/wd/hub";

        @BeforeTest
        public void setUp() throws Exception {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("browserName", "chrome");
            capabilities.setCapability("version", "96.0");
            capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
            capabilities.setCapability("build", "AutomationUsingFindElement");
            capabilities.setCapability("name", "AutomationUsingFindElementSuite");
            try {
                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
            } catch (MalformedURLException e) {
                System.out.println("Invalid grid URL");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }

        @Test
        public void findElementsByXPath() {
            try {
                System.out.println("Logging into Lambda Test Selenium Playground Page");
                driver.get("https://www.lambdatest.com/selenium-playground/");

                List&amp;lt;WebElement&amp;gt; sectionHeaders= driver.findElements(By.xpath("//h2[@class='st_heading']"));
                for(WebElement e: sectionHeaders){
                    System.out.println("The list of headers are:"+e.getText());
                }
            } catch (Exception e) {

            }

        }

        @AfterTest
        public void closeBrowser() {
            driver.close();
            System.out.println("The driver has been closed.");

        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;@ Test(findElementsByXPath): In this case, we are locating the section headers using XPath and storing them in a list of web elements. Later, we iterated through the list and printed their text.&lt;/p&gt;

&lt;p&gt;The remaining areas remain the same as we did in the Code Walkthrough of our first example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; sectionHeaders= driver.findElements(By.xpath("//h2[[@class](http://twitter.com/class)='st_heading']"));
                for(WebElement e: sectionHeaders){
                    System.out.println("The list of headers are:"+e.getText());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Console Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you run the above test case, your console output would look something like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2546%2F1%2ArQU7__bMsP_f_HvJBTnI8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2546%2F1%2ArQU7__bMsP_f_HvJBTnI8Q.png" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can also view your test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3454%2F1%2AbqWGDdsTkRvQ3qj_C8LwCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3454%2F1%2AbqWGDdsTkRvQ3qj_C8LwCg.png" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon completion of the test, test results will be displayed on the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr07_pk&amp;amp;utm_term=pk&amp;amp;utm_content=Blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The dashboard shows all the details and metrics related to your tests.&lt;/p&gt;

&lt;p&gt;Navigate to the LambdaTest Analytics Dashboard to view the metrics of your tests. The Test Overview will allow you to quickly assess test performance and overall health. Meanwhile, the Test Summary will show how many passes and fails your team has run and the overall efficacy of these tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4SitZXK9us-ayjn-PyInkA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4SitZXK9us-ayjn-PyInkA.gif" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re a developer who’s looking to take your development and test engineering skills to the next level, this Selenium 101 certification from LambdaTest can help you reach that goal.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qx9FPFfJm7E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article on the difference between findElement and findElements in Selenium, we learned about what is findElement and findElements in Selenium Java and had a glance at their major differences. We also saw the various implementations of findElement using ID, Name, ClassName, TagName, etc. In the end, we also implemented a use case using findElements.&lt;/p&gt;

&lt;p&gt;Hope you enjoyed reading this article and learned something new about Find Element.&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>css</category>
      <category>computerscience</category>
      <category>codenewbie</category>
      <category>testing</category>
    </item>
    <item>
      <title>How To Handle Multiple Windows In Selenium WebDriver Using Java?</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Wed, 06 Apr 2022 11:00:23 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-handle-multiple-windows-in-selenium-webdriver-using-java-1kol</link>
      <guid>https://forem.com/testmuai/how-to-handle-multiple-windows-in-selenium-webdriver-using-java-1kol</guid>
      <description>&lt;p&gt;When automating any website or a web application in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;, you might have come across a scenario where multiple windows open within an application when a button is clicked, and appropriate action needs to be performed on the opened windows. Alas, you might not be in a position to work on all windows at the same time. Hence there is a need for some mechanism through which you can gain control over the parent and child windows.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-java?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Java tutorial&lt;/a&gt;, we will understand what Windows are and how to handle multiple windows in Selenium WebDriver using Java.&lt;/p&gt;

&lt;p&gt;Starting your journey with Selenium WebDriver? Check out this step-by-step guide to perform Automation testing using &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s get started!!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Window in Selenium?
&lt;/h2&gt;

&lt;p&gt;A window in any browser is the main web page on which the user lands after hitting a URL. Such a window in Selenium is referred to as the &lt;strong&gt;Parent Window&lt;/strong&gt; or &lt;strong&gt;Main Window&lt;/strong&gt;. It opens when the Selenium WebDriver session is created and has all the focus of the WebDriver.&lt;/p&gt;

&lt;p&gt;For example, when you open any website or link, the page you land in is the Main Window.&lt;br&gt;
Here, I am logging into the &lt;a href="http://labs.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LambdaTest, and the below-shown window is the Main Window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2ASQrYHqb6p1PxWUb2C5Iizg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2928%2F1%2ASQrYHqb6p1PxWUb2C5Iizg.png" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that supports Selenium Grid, providing a solution to every obstacle you face while performing &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; on your local machine. &lt;a href="https://www.lambdatest.com/automation-testing-tool?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation testing tools&lt;/a&gt; like LambdaTest offer a cloud-based Selenium Grid consisting of an &lt;a href="https://www.lambdatest.com/online-device-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online device farm&lt;/a&gt; of 3000+ real browsers and operating systems for you to perform &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt; at scale.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WZlsHlReRww"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to identify parent and child windows in Selenium?
&lt;/h2&gt;

&lt;p&gt;As discussed in the above section of this blog on how to handle multiple windows in Selenium WebDriver using Java, when you open any website, the main page where you will perform any operation is the &lt;strong&gt;Parent Window&lt;/strong&gt;. This is the same webpage that will open when the Selenium automation script is executed.&lt;/p&gt;

&lt;p&gt;Now, all the other windows that open inside your main window are termed as &lt;strong&gt;Child Windows&lt;/strong&gt;. In order to understand this better, let’s log in to the Selenium Playground and use the &lt;a href="https://www.lambdatest.com/selenium-playground/window-popup-modal-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Window Popup Model&lt;/a&gt; option.&lt;/p&gt;

&lt;p&gt;Once you click on the Window Popup Model option, the page you land in is the Parent Window, and the window which opens by clicking on Follow On Twitter option is the Child Window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2874%2F1%2AEuk98JmugTzhZMhKkvmTgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2874%2F1%2AEuk98JmugTzhZMhKkvmTgg.png" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is important to note that there can be single or multiple child windows inside your parent window.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Window Handle in Selenium?
&lt;/h2&gt;

&lt;p&gt;Now that you have understood the concept of Windows in Selenium let’s look at how to control these different browser windows. This is where the Window &lt;strong&gt;Handle&lt;/strong&gt; comes into the picture.&lt;/p&gt;

&lt;p&gt;A window handle stores the unique address of the browser windows. It is just a pointer to a window whose return type is alphanumeric. The window handle in Selenium helps in handling multiple windows and child windows. Each browser window has a unique window handle value through which it can be identified.&lt;/p&gt;

&lt;p&gt;In the previous section of this article on how to handle multiple windows in Selenium WebDriver using Java, when a new window was opened by clicking on the Follow On Twitter option, it had its Window Handle (or ID). This helps to switch the Selenium WebDriver context to the corresponding window and perform any operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver 4&lt;/a&gt; is a major architectural update in Selenium 4. WebDriver is the de facto standard for automating web browsers, enabling you to run automated tests on a variety of browsers. Follow along with this video to learn &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what’s new in Selenium 4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Mmp_FiNIYtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the different methods used for window handling in Selenium?
&lt;/h2&gt;

&lt;p&gt;Let’s see what are the different methods through which we can handle these windows in Selenium. Selenium WebDriver provides us with various methods for handling windows. Below are a few of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;getWindowHandle()&lt;/strong&gt;: With this method, we get a unique ID of the current window which will identify it within this driver instance. This method will return the value of the String type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;getWindowHandles( )&lt;/strong&gt;: With this method, we get the IDs of all the windows opened by the web driver. Its return type is Set .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;switchTo()&lt;/strong&gt;: Using this method, we can perform switch operations within windows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to handle a single child window in Selenium?
&lt;/h2&gt;

&lt;p&gt;Let us now implement a code snippet for handling the single-child window in Selenium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to the Window &lt;a href="https://www.lambdatest.com/selenium-playground/window-popup-modal-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Popup Modal Demo&lt;/a&gt; page of Selenium Playground.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on Follow On Twitter option in the Single Window Popup section&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch to the child window opened&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Print the header of the web page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2792%2F1%2AgYmAURatpvSN71pLL_VlLg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2792%2F1%2AgYmAURatpvSN71pLL_VlLg.png" width="800" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will implement the case using Selenium with Java and use the cloud Selenium grid offered by LambdaTest for executing our test case.&lt;/p&gt;

&lt;p&gt;Selenium Grid refers to a software testing setup that enables QAs to perform parallel tests across multiple browsers and devices with unique operating systems. When the entire setup of Selenium Grid is accessible using cloud-based servers, it is called Selenium Grid on Cloud. An &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt; helps you focus on writing better Selenium test scripts rather than worrying about infrastructure maintenance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MultipleWindowsInSelenium.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;

[@Listeners](http://twitter.com/Listeners)({util.Listener.class})
class MultipleWindowsInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

    [@BeforeTest](http://twitter.com/BeforeTest)
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "96.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "MultipleWindowsInSelenium");
        capabilities.setCapability("name", "MultipleWindowsInSeleniumTest");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.get("[https://www.lambdatest.com/selenium-playground/window-popup-modal-demo](https://www.lambdatest.com/selenium-playground/window-popup-modal-demo)");

    }


    [@Test](http://twitter.com/Test)
    public void singleWindowPopUp() {
        try {
            //Clicks on the follow on twitter option
            WebElement followOnTwitter = driver.findElement(By.xpath("//a[text()='  Follow On Twitter ']"));
            followOnTwitter.click();

            // To handle parent window
            String MainWindow = driver.getWindowHandle();
            System.out.println("Main window handle is " + MainWindow);

            // To handle child window
            Set&amp;lt;String&amp;gt; s1 = driver.getWindowHandles();
            System.out.println("Child window handle is" + s1);
            Iterator&amp;lt;String&amp;gt; i1 = s1.iterator();
            while (i1.hasNext()) {
                String ChildWindow = i1.next();
                if (!MainWindow.equalsIgnoreCase(ChildWindow)) {
                    driver.switchTo().window(ChildWindow);
                    String pageTitle=driver.getTitle();
                    System.out.println("The web page title of child window is:"+pageTitle);
                    driver.close();
                    System.out.println("Child window closed");
                }
            }

        } catch (Exception e) {

        }

    }

    [@AfterTest](http://twitter.com/AfterTest)
    public void closeBrowser() {
        driver.quit();
        Reporter.log("The driver has been closed.", false);

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below testng.xml file for running the above testcase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;testng.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite  name="MultipleWindowsInSeleniumSuite"&amp;gt;

    &amp;lt;test name="MultipleWindowsInSeleniumTest" &amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name="LambdaTest.MultipleWindowsInSelenium" &amp;gt;
            &amp;lt;/class&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And the below pom.xml file for installing all the necessary dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pom.xml&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0)"
         xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"
         xsi:schemaLocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0) [http://maven.apache.org/xsd/maven-4.0.0.xsd](http://maven.apache.org/xsd/maven-4.0.0.xsd)"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-api&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-remote-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;

    &amp;lt;properties&amp;gt;
        &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
        &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
    &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us now see the different areas of code in detail.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Imported Dependencies&lt;/strong&gt;: Here, we have imported all the necessary classes of Selenium WebDriver, WebDriverWait, Desired Capabilities, and RemoteWebDriver to set the respective browser capabilities and run &lt;a href="https://www.lambdatest.com/selenium-ide-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE tests on cloud&lt;/a&gt; grid.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeo0f359lhzsd8weq8gn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeo0f359lhzsd8weq8gn.png" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: As we have used a Selenium Grid Cloud like LamdaTest to perform our test execution, we are using the below-shown variables.&lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2304%2F1%2Ajp2hTiojwAJ5Q3Hxf5boVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2304%2F1%2Ajp2hTiojwAJ5Q3Hxf5boVg.png" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have also used the &lt;a href="https://www.lambdatest.com/blog/java-event-listeners/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Java Listener class&lt;/a&gt; here in order to customize the TestNG Report. TestNG provides us with a lot of Listeners (e.g., IAnnotationTransformer, IReporter, etc.). These interfaces are used while performing Selenium automation testing mainly to generate logs and customize the TestNG reports. &lt;/p&gt;

&lt;p&gt;To implement the Listener class, you can simply add an annotation in your test class just above your class name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@Listeners](http://twitter.com/Listeners)(PackageName.ClassName.class)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. @BeforeTest(Setup Method)&lt;/strong&gt;: Here, we have used the LambdaTest &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Desired Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Remote WebDriver&lt;/a&gt;. After that, we are opening the Window Popup Demo Page in the launched browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3168%2F1%2AdmCDgYYc2lbiYkb0eEA75Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3168%2F1%2AdmCDgYYc2lbiYkb0eEA75Q.png" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;(singleWindowPopup)&lt;/strong&gt;: Here, we are first locating the Web Element for Follow On Twitter option and clicking on it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2868%2F1%2A04AyOzgNUCEXZDbI3UyWeA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2868%2F1%2A04AyOzgNUCEXZDbI3UyWeA.png" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next step, we store the handles of all the opened windows in a Set of String.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2772%2F1%2ANl_uLeRpPMenOsTrdE2kvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2772%2F1%2ANl_uLeRpPMenOsTrdE2kvw.png" width="800" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we start iterating over the set of window handles we have by using the driver.switchTo() method, we switch to the child window. After switching to the child window, we print the web page title and close the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AmZuZJAtTz6Z32eAuEU8h2A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AmZuZJAtTz6Z32eAuEU8h2A.png" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. @AfterTest(closeBrowser)&lt;/strong&gt;: Here, we are just closing the launched browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff8fpr5sqobsqv60u6xsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff8fpr5sqobsqv60u6xsd.png" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can also view your test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AhCyC-IkhfrWmHNAypWA4Kw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AhCyC-IkhfrWmHNAypWA4Kw.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With LambdaTest, you can see how your &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt; efforts are going. You’ll get real-time reports on the performance of your test suites and an automated system to track change impact across all your automation efforts. You can use &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Analytics&lt;/a&gt; to get insight into this information and drive better testing practices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWErW4cf6Hxs2x-YgkzkJbQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AWErW4cf6Hxs2x-YgkzkJbQ.png" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you run the test case, the console output will look something like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AmxSLcUsFgsbyTeBUUNHUoQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AmxSLcUsFgsbyTeBUUNHUoQ.png" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.openqa.selenium.remote.ScreenshotException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_page" rel="noopener noreferrer"&gt;org.openqa.selenium.remote.ScreenshotException&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This exception raised by selenium webdriver when the selenium is unable to take the screenshot or capture the current screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to handle multiple child windows in Selenium?
&lt;/h2&gt;

&lt;p&gt;When it comes to handling multiple child windows in Selenium, the overall process remains the same as we do for a single child window. However, in the case of multiple child windows, you can use any of the available conditional operators like if-else, switch etc. and do the operations, which are particular to each child window.&lt;/p&gt;

&lt;p&gt;Let us write our script for handling one of such scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to the Window &lt;a href="https://www.lambdatest.com/selenium-playground/window-popup-modal-demo?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Popup Modal Demo&lt;/a&gt; page of Selenium Playground.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on Follow On Twitter and Facebook in the Multiple Window Popup section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch to each of the child windows opened.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Sign Up button for Facebook Window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Sign Up button for Twitter Window.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MultipleWindowsInSelenium.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.reporters.jq.Main;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;

[@Listeners](http://twitter.com/Listeners)({util.Listener.class})
class MultipleWindowsInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

    [@BeforeTest](http://twitter.com/BeforeTest)
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "97.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "MultipleWindowsInSelenium");
        capabilities.setCapability("name", "MultipleWindowsInSeleniumTest");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        driver.get("[https://www.lambdatest.com/selenium-playground/window-popup-modal-demo](https://www.lambdatest.com/selenium-playground/window-popup-modal-demo)");

    }


    [@Test](http://twitter.com/Test)
    public void multipleWindowPopUp() {
        try {
            //Clicks on the follow on twitter and facebook option
            WebElement followOnTwitterAndFacebook = driver.findElement(By.xpath("//a[text()='Follow Twitter &amp;amp; Facebook']"));
            followOnTwitterAndFacebook.click();

            // To handle parent window
            String MainWindow = driver.getWindowHandle();
            System.out.println("Main window handle is " + MainWindow);

            // To handle child window
            Set&amp;lt;String&amp;gt; s1 = driver.getWindowHandles();
            System.out.println("Child window handle is" + s1);
            Iterator&amp;lt;String&amp;gt; i1 = s1.iterator();
            while (i1.hasNext()) {
                String ChildWindow = i1.next();
                if (!MainWindow.equalsIgnoreCase(ChildWindow)) {
                    driver.switchTo().window(ChildWindow);
                    String pageTitle=driver.getTitle();
                    System.out.println("The web page title of child window is:"+pageTitle);
                    if(pageTitle.contains("Facebook")){
                        WebElement signUpForFB= driver.findElement(By.xpath("//span[text()='Create New Account']"));
                        signUpForFB.click();
                        System.out.println("Clicked on Login Option For Facebook");
                    }else if(pageTitle.contains("Twitter")){
                        WebElement signUpForTwitter= driver.findElement(By.xpath("//span[text()='Sign up for Twitter']"));
                        signUpForTwitter.click();
                        System.out.println("Clicked on Follow Option For Twitter");
                    }
                }
            }

        } catch (Exception e) {
               e.printStackTrace();
        }

    }

    [@AfterClass](http://twitter.com/AfterClass)
    public void closeBrowser() {
        driver.quit();
        System.out.println("Closing the browser");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this case, the process of iterating the child windows is exactly the same as how we did it in the case of a single child window. However, here we are distinguishing the windows respective to Facebook and Twitter by making use of their corresponding titles and by making use of if-else statements, we are clicking on their respective Sign Up buttons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A-xR519b-nWHxoH31O5ZBzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A-xR519b-nWHxoH31O5ZBzA.png" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you run the test case, the console output will look something like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2482%2F1%2A2P9_JfiX31N2rjpnP5WKTw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2482%2F1%2A2P9_JfiX31N2rjpnP5WKTw.png" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to switch back from child window to parent window in Selenium?
&lt;/h2&gt;

&lt;p&gt;You saw how we switch to a child window from the parent window. Now, once the WebDriver has control of the child window, it has control only on that and you can no longer perform any operation in the parent window. So how do we switch back to the parent window in case we need to?&lt;/p&gt;

&lt;p&gt;This can be simply done by using the **switchTo() **function. This function helps in shifting the focus back to the parent window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let us see how to implement the switchTo*&lt;em&gt;()&lt;/em&gt;* function. We will implement the same use case as discussed in the last section of this article on how to handle multiple windows in Selenium WebDriver using Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MultipleWindowsInSelenium.java&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.reporters.jq.Main;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;

[@Listeners](http://twitter.com/Listeners)({util.Listener.class})
class MultipleWindowsInSelenium {


    public String username = "YOUR USERNAME";
    public String accesskey = "YOUR ACCESSKEY";
    public static RemoteWebDriver driver = null;
    public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

    [@BeforeTest](http://twitter.com/BeforeTest)
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("version", "97.0");
        capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
        capabilities.setCapability("build", "MultipleWindowsInSelenium");
        capabilities.setCapability("name", "MultipleWindowsInSeleniumTest");
        try {
            driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
        } catch (MalformedURLException e) {
            System.out.println("Invalid grid URL");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }


    [@Test](http://twitter.com/Test)
    public void switchToParentWindow() {
        try {
            //Clicks on the follow on twitter option
            WebElement followOnTwitter = driver.findElement(By.xpath("//a[text()='  Follow On Twitter ']"));
            followOnTwitter.click();

            // To handle parent window
            String MainWindow = driver.getWindowHandle();
            System.out.println("Main window handle is " + MainWindow);

            // To handle child window
            Set&amp;lt;String&amp;gt; s1 = driver.getWindowHandles();
            System.out.println("Child window handle is" + s1);
            Iterator&amp;lt;String&amp;gt; i1 = s1.iterator();
            while (i1.hasNext()) {
                String ChildWindow = i1.next();
                if (!MainWindow.equalsIgnoreCase(ChildWindow)) {
                    driver.switchTo().window(ChildWindow);
                    String pageTitle=driver.getTitle();
                    System.out.println("The web page title of child window is:"+pageTitle);
                    driver.close();
                    System.out.println("Child window closed");
                }
            }
            System.out.println("Switched back to parent window");
            driver.switchTo().window(MainWindow);
            driver.close();

        } catch (Exception e) {

        }

    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this test case, after navigating to the child window and closing it. We specifically switch back to the parent window and close that too, and as a result, we don’t need to close the browser again after the test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AhD7cRsk-xH4I9mAOs46Jng.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2AhD7cRsk-xH4I9mAOs46Jng.png" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Console Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you run the test case, the console output will look something like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2644%2F1%2AMn24WGuE98j2T8vwcRC5kg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2644%2F1%2AMn24WGuE98j2T8vwcRC5kg.png" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.openqa.selenium.ScriptTimeoutException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr06_pk&amp;amp;utm_term=pk&amp;amp;utm_content=web_page" rel="noopener noreferrer"&gt;org.openqa.selenium.ScriptTimeoutException&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The WebDriver error — script timeout error happens when a user script fails to complete before the script timeout duration of the session expires.&lt;/p&gt;

&lt;p&gt;The script timeout duration is a configurable capability — meaning you can change how long it takes for the driver to interrupt an injected script. The driver will wait up to 30 seconds, by default, before interrupting the script and returning with a script timeout error. This can be modified to be longer, shorter, or indefinite.&lt;/p&gt;

&lt;p&gt;If the session script timeout duration is set to null, the timeout duration to becomes indefinite, and there is a risk of a non-recoverable session state.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to close all windows while handling multiple windows in Selenium?
&lt;/h2&gt;

&lt;p&gt;While we are handling multiple windows in Selenium, it is very important to understand how you can actually close the windows.&lt;/p&gt;

&lt;p&gt;As you saw in the above example, in order to close the parent window, we had to explicitly switch to the parent window and then close it using the &lt;strong&gt;driver.close()&lt;/strong&gt; method. The driver.close() method helps us to close the driver, which is being controlled at the moment. But what if we want to close all the opened windows at once?&lt;/p&gt;

&lt;p&gt;In such cases, the method which can come in handy is the &lt;strong&gt;driver.quit()&lt;/strong&gt;. The &lt;strong&gt;driver.quit()&lt;/strong&gt; method closes all the open windows regardless of where the control is lying.&lt;/p&gt;

&lt;p&gt;So now you know what to use when you want to tackle all the open windows at once! 🙂&lt;/p&gt;

&lt;p&gt;This certification demonstrates your knowledge of Selenium and Java, and your expertise at automating tests for any project.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium Java 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vUxfvuAI7kE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article on how to handle multiple windows in Selenium WebDriver using Java, we read about Windows in Selenium. We saw what are Parent and Child Windows and how we can handle them using their corresponding Window Handles. We also implemented the automation script for handling both single and multiple child windows. Additionally, we learned about switching back to the parent window, and the trick of closing all the opened windows at once.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article on how to handle multiple windows in Selenium WebDriver using Java, and it helps you in handling multiple windows for your Selenium automation 🙂&lt;/p&gt;

&lt;p&gt;Happy Testing !!&lt;/p&gt;

</description>
      <category>java</category>
      <category>testing</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How To Find Element By Text In Selenium WebDriver</title>
      <dc:creator>Riadayal</dc:creator>
      <pubDate>Tue, 05 Apr 2022 17:18:10 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-find-element-by-text-in-selenium-webdriver-1l58</link>
      <guid>https://forem.com/testmuai/how-to-find-element-by-text-in-selenium-webdriver-1l58</guid>
      <description>&lt;p&gt;Find element by Text in &lt;a href="https://www.lambdatest.com/selenium?utm_source=hashnode&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep09_rd&amp;amp;utm_term=rd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is used to locate a web element using its text attribute. The text value is used mostly when the basic element identification properties such as ID or Class are dynamic in nature, making it hard to locate the web element.&lt;/p&gt;

&lt;p&gt;Sometimes, developers tend to group similar web elements with the same ID or the same Class together. For example, if you have an element with the tag as Button which has a dynamic ID and Class name, where ID is getting changed from ‘ID-3465-text1’ to ‘ID-4434-textE2,’ and the Class name gets changed from “ID-Class-text45” to “ID-Class-text73” on every new session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5hu8gvjpd0ivw5wjgx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5hu8gvjpd0ivw5wjgx3.png" width="498" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In such cases, it becomes very difficult to &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;locate the web elements&lt;/a&gt; using ID or Class attribute, and this is when the Text attribute comes to the rescue while performing &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The text value can be fully matched or partially matched to locate the element. In this article on how to find element by text in &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;, you will read about how to use the Text attribute in order to find any element.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Find Element In Selenium?
&lt;/h2&gt;

&lt;p&gt;When you start &lt;a href="https://www.lambdatest.com/blog/how-to-write-test-scripts-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;writing your Selenium automation script&lt;/a&gt;, interaction with web elements becomes your first and a very vital step because it’s the WebElements that you play around with within your test script. Now, interaction with these web elements can only happen if you identify them using the right approach.&lt;/p&gt;

&lt;p&gt;Find Element method in Selenium is a command which helps you identify a web element. There are multiple ways that Find Element provides to uniquely identify a web element within the web page using &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Web locators in Selenium&lt;/a&gt; like ID, Name, Class Name, etc. Here is the syntax of Find Element In Selenium.&lt;/p&gt;

&lt;p&gt;The syntax of Find Element is&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement elementName= driver.findElement(By.&amp;lt;LocatorStrategy&amp;gt;("LocatorValue"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As shown in the above syntax, this command accepts the “&lt;strong&gt;By&lt;/strong&gt;” object as the argument and returns a WebElement object. The “&lt;strong&gt;By&lt;/strong&gt;” is a locator or query object and accepts the locator strategy. The Locator Strategy can assume the below values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tag Name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial Link Text&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XPath&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Selector&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Find Element By Text in Selenium?
&lt;/h2&gt;

&lt;p&gt;We saw in the previous section about find element in Selenium and its syntax. Now, you must be wondering how to find element by text in Selenium WebDriver.&lt;/p&gt;

&lt;p&gt;The answer is by making use of &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath in Selenium&lt;/a&gt;!!&lt;/p&gt;

&lt;p&gt;Wondering how? Let’s look at the sections below.&lt;/p&gt;

&lt;p&gt;In order to use Text, you will need to make use of XPath as your Locator Strategy and the text attribute of the element in the Locator Value.&lt;/p&gt;

&lt;p&gt;The basic format of XPath in Selenium is as below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;XPath = //tagname[[@Attribute](http://twitter.com/Attribute)=’Value’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;However, before we get started, it’s important to understand two built-in methods of Selenium, which will ultimately be used in findElement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. text()&lt;/strong&gt; — This is a built-in method in Selenium that is used with XPath in order to locate an element based on its exact text value. The syntax of using text() with findElement is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement ele = driver.findElement(By.xpath(“//&amp;lt;tagName&amp;gt;[text()=’text value’]”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. contains()&lt;/strong&gt; — Similar to the text() method, contains() is another built-in method which is used with XPath. However, this is used when we want to write the locator based on a partial text match. The syntax of using text() &amp;amp; contains() with findElement is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement ele=driver.findElement(By.xpath(“//&amp;lt;tagName&amp;gt;[contains(text(),’textvalue’)]”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let us now read about these in detail.&lt;/p&gt;

&lt;p&gt;Note: The &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.openqa.selenium.safari.ConnectionClosedException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;ConnectionClosedException&lt;/a&gt; occured whenever connection between driver and client has been lost and client is sending the request to the driver after disconnecting the driver.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by Text in Selenium for Complete Text match
&lt;/h2&gt;

&lt;p&gt;Now that you saw the syntax for using text() in case of complete text match. In this section on how to find element by text in Selenium, let us see it using an example.&lt;/p&gt;

&lt;p&gt;We will use &lt;a href="https://www.lambdatest.com/selenium-playground/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Playground&lt;/a&gt; offered by LambdaTest for understanding the same. LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that supports Selenium Grid, providing a solution to every obstacle you face while performing automation testing using your local machine. Test Automation Platforms like LambdaTest offer a Selenium Grid consisting of 3000+ &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; for you to perform Selenium automation testing effortlessly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznlu2xigt84niux832mo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznlu2xigt84niux832mo.png" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to Selenium Playground.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify the Web Element for the Checkbox Demo link on the above web page using the text() method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on it and print the page header.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;We will implement the case using &lt;a href="https://www.lambdatest.com/learning-hub/selenium-java?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium with Java&lt;/a&gt; and use the cloud Selenium Grid offered by LambdaTest for executing our test case.&lt;br&gt;
Selenium Grid refers to a software testing setup that enables QAs to perform &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt; across multiple browsers and devices with unique operating systems. When the entire setup of Selenium Grid is accessible using cloud-based servers, it is called &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid Cloud&lt;/a&gt;. An online Selenium Grid helps you focus on writing better Selenium test scripts rather than worrying about infrastructure maintenance.&lt;/p&gt;

&lt;p&gt;Let us now inspect the locator for the Checkbox Demo page. In order to inspect, you can simply right-click on the Web Element and click on Inspect. On the Elements tab, you can start writing your locator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2etw9i1t846cxw2d1q64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2etw9i1t846cxw2d1q64.png" width="800" height="605"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the above picture, we use the Checkbox Demo text with its tag a for a complete match, and hence, the correct implementation here would be:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement checkbox= driver.findElement(By.xpath(“//a[text()=’Checkbox Demo’]”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let us now use the same and write our test case.&lt;/p&gt;

&lt;p&gt;You can refer to the below testcase.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

    import org.openqa.Selenium.By;
    import org.openqa.Selenium.WebElement;
    import org.openqa.Selenium.remote.DesiredCapabilities;
    import org.openqa.Selenium.remote.RemoteWebDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.List;

    [@Listeners](http://twitter.com/Listeners)({util.Listener.class})
    class AutomationUsingFindElementByText {

        public String username = "YOUR USERNAME";
        public String accesskey = "YOUR ACCESSKEY";
        public static RemoteWebDriver driver = null;
        public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

        [@BeforeTest](http://twitter.com/BeforeTest)
        public void setUp() throws Exception {
           DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("browserName", "chrome");
            capabilities.setCapability("version", "96.0");
            capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
            capabilities.setCapability("build", "AutomationUsingFindElement");
            capabilities.setCapability("name", "AutomationUsingFindElementSuite");
            try {
                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
            } catch (MalformedURLException e) {
                System.out.println("Invalid grid URL");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }



        [@Test](http://twitter.com/Test)
        public void findElementByCompleteTextMatch() {
            try {
                System.out.println("Logging into Lambda Test Selenium Playground");
                driver.get("[http://labs.lambdatest.com/Selenium-playground/](http://labs.lambdatest.com/Selenium-playground/)");

                WebElement checkBoxDemoPage= driver.findElement(By.xpath("//a[text()='Checkbox Demo']"));
                checkBoxDemoPage.click();
                System.out.println("Clicked on the Checkbox Demo Page");

                WebElement header=driver.findElement(By.xpath("//h1"));
                System.out.println("The header of the page is:"+header.getText());
            } catch (Exception e) {

            }

        }


        [@AfterTest](http://twitter.com/AfterTest)
        public void closeBrowser() {
            driver.close();
            System.out.println("The driver has been closed.");

        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You can use the below testng.xml file for running the above testcase.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite  name="AutomationUsingFindElementSuite"&amp;gt;

    &amp;lt;test name="AutomationUsingFindElementTest" &amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name="LambdaTest.AutomationUsingFindElementByText" &amp;gt;
            &amp;lt;/class&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And the below pom.xml file for installing all the necessary dependencies.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0)"
         xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"
         xsi:schemaLocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0) [http://maven.apache.org/xsd/maven-4.0.0.xsd](http://maven.apache.org/xsd/maven-4.0.0.xsd)"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;

    &amp;lt;groupId&amp;gt;org.example&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;LambdaTest&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.Seleniumhq.Selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;Selenium-api&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.Seleniumhq.Selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;Selenium-remote-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.Seleniumhq.Selenium&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;Selenium-chrome-driver&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.0.0-alpha-7&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.testng&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;testng&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;6.14.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;io.github.bonigarcia&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;webdrivermanager&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;4.4.3&amp;lt;/version&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;

    &amp;lt;properties&amp;gt;
        &amp;lt;maven.compiler.source&amp;gt;8&amp;lt;/maven.compiler.source&amp;gt;
        &amp;lt;maven.compiler.target&amp;gt;8&amp;lt;/maven.compiler.target&amp;gt;
    &amp;lt;/properties&amp;gt;

&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;p&gt;In this section on how to find element by text in Selenium, let’s look at the different areas of code in detail.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Imported Dependencies&lt;/strong&gt;: Here, we have imported all the necessary classes of Selenium WebDriver, WebDriverWait, Desired Capabilities, and RemoteWebDriver to set the respective browser capabilities and run the test cases on the grid.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeo0f359lhzsd8weq8gn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeo0f359lhzsd8weq8gn.png" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Global Variables&lt;/strong&gt;: As we have used a Selenium Grid Cloud like LambdaTest to perform our test execution, we are using the below-shown variables. &lt;/p&gt;

&lt;p&gt;Here, you can populate the values for your corresponding username and access key, which can be collected by logging into your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Profile Section&lt;/a&gt;. You can copy the Username and the Access Token to be used in the code. However, the grid URL will remain the same, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetb0g9psft13cbkrwjn3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fetb0g9psft13cbkrwjn3.png" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have also used the &lt;a href="https://www.lambdatest.com/blog/java-event-listeners/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Listener class&lt;/a&gt; here in order to customize the TestNG Report. TestNG provides us with a lot of Listeners (e.g., IAnnotationTransformer, IReporter, etc.). These interfaces are used while performing Selenium automation testing mainly to generate logs and customize the TestNG reports.&lt;/p&gt;

&lt;p&gt;To implement the Listener class, you can simply add an annotation in your test class just above your class name.&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[@Listeners](http://twitter.com/Listeners)(PackageName.ClassName.class)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F76o7zog9nzru6lo532c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F76o7zog9nzru6lo532c6.png" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. @BeforeTest(Setup Method)&lt;/strong&gt;: Here, we have used the LambdaTest Desired &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Capabilities Generator&lt;/a&gt; and have set the necessary capabilities of browser name, version, platform, etc., for our &lt;a href="https://www.lambdatest.com/blog/selenium-remotewebdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Remote WebDriver&lt;/a&gt;. After that, we are opening the website in the launched browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxu97wfv05ulpu1nwavd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxu97wfv05ulpu1nwavd.png" width="800" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;(findElementByCompleteTextMatch)&lt;/strong&gt;: In this case, we are first logging into the Selenium Playground web page. After that, we locate the Checkbox Demo button using a complete text match and click on the same. In the end, we are printing the header of the web page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2zcp1um868sz21ko6ta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2zcp1um868sz21ko6ta.png" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06oaku492ov4rmr05397.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06oaku492ov4rmr05397.png" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. @AfterTest(closeBrowser)&lt;/strong&gt;: Here, we are just closing the launched browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff8fpr5sqobsqv60u6xsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff8fpr5sqobsqv60u6xsd.png" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can also view your test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/dashboard?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhe67yvrut6ox6fmuaft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhe67yvrut6ox6fmuaft.png" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Console Output
&lt;/h2&gt;

&lt;p&gt;Once you run the test case, the console output will look something like the below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m0qvpfo3pzh31mpignk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m0qvpfo3pzh31mpignk.png" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/VeV_sup5S8E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around Selenium testing, &lt;a href="https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress E2E testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Note: The &lt;a href="https://www.lambdatest.com/automation-testing-advisor/selenium/classes/org.openqa.selenium.remote.http.ConnectionFailedException?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;ConnectionFailedException&lt;/a&gt; occured when client is not able to establish connection with selenium hub or webdriver endpoints.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find Element by Text in Selenium for Partial Text match
&lt;/h2&gt;

&lt;p&gt;In the previous example of this article on how to find element by text in Selenium WebDriver, you saw how you could use findElement by Text for a complete text match. In this section, we will understand how we can use partial Text match in order to locate web elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Case
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to Selenium Playground.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify all the Web Elements which have a table in their names.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Print the text of all such Web Elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbup1bttbrpmorvbu8ps3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbup1bttbrpmorvbu8ps3.png" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us see the locator for the above test case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3114%2F1%2AEcOg1zg99JtfchqvgtuaUQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3114%2F1%2AEcOg1zg99JtfchqvgtuaUQ.png" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the above picture, we use the Table text with its tag a for a partial match, and as a result, we get a total of 5 Web Elements using the above locator. Since there are more than 1 Web Element, in this case, we will use FindElements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FindElements&lt;/strong&gt; in Selenium returns you the list of web elements that match the locator value, unlike FindElement which returns only a single web element. In case, there are no matching elements within the web page, FindElements returns an empty list.&lt;/p&gt;

&lt;p&gt;The syntax of FindElements in Selenium is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; listName= driver.findElements(By.&amp;lt;LocatorStrategy&amp;gt;(“LocatorValue”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Hence, the correct implementation using FindElements with partial text match here would be:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;WebElement&amp;gt; tableOptions=driver.findElements(By.xpath(“//a[contains(text(),’Table’)”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let us now use the same and write our test case.&lt;/p&gt;

&lt;p&gt;You can refer to the below testcase.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

    import org.openqa.Selenium.By;
    import org.openqa.Selenium.WebElement;
    import org.openqa.Selenium.remote.DesiredCapabilities;
    import org.openqa.Selenium.remote.RemoteWebDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Listeners;
    import org.testng.annotations.Test;

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.List;

    [@Listeners](http://twitter.com/Listeners)({util.Listener.class})
    class AutomationUsingFindElementByText {

        public String username = "YOUR USERNAME";
        public String accesskey = "YOUR ACCESSKEY";
        public static RemoteWebDriver driver = null;
        public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";

        [@BeforeTest](http://twitter.com/BeforeTest)
        public void setUp() throws Exception {
           DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("browserName", "chrome");
            capabilities.setCapability("version", "96.0");
            capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one
            capabilities.setCapability("build", "AutomationUsingFindElement");
            capabilities.setCapability("name", "AutomationUsingFindElementSuite");
            try {
                driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
            } catch (MalformedURLException e) {
                System.out.println("Invalid grid URL");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }

        [@Test](http://twitter.com/Test)
        public void findElementByPartialTextMatch() {
            try {
                System.out.println("Logging into Lambda Test Selenium Playground");
                driver.get("[http://labs.lambdatest.com/Selenium-playground/](http://labs.lambdatest.com/Selenium-playground/)");
                List&amp;lt;WebElement&amp;gt; tableOptions= driver.findElements(By.xpath("//a[contains(text(),'Table')]"));
                for(WebElement e: tableOptions){
                    System.out.println("The different options with table in name are:"+e.getText());
                }

            } catch (Exception e) {

            }

        }

        [@AfterTest](http://twitter.com/AfterTest)
        public void closeBrowser() {
            driver.close();
            System.out.println("The driver has been closed.");

        }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the below testng.xml file for running the above testcase.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)"&amp;gt;
&amp;lt;suite  name="AutomationUsingFindElementSuite"&amp;gt;

    &amp;lt;test name="AutomationUsingFindElementTest" &amp;gt;
        &amp;lt;classes&amp;gt;
            &amp;lt;class name="LambdaTest.AutomationUsingFindElementByText" &amp;gt;
            &amp;lt;/class&amp;gt;
        &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And the below pom.xml file for installing all the necessary dependencies.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;
&amp;lt;project xmlns="&lt;a href="http://maven.apache.org/POM/4.0.0" rel="noopener noreferrer"&gt;http://maven.apache.org/POM/4.0.0&lt;/a&gt;"&lt;br&gt;
         xmlns:xsi="&lt;a href="http://www.w3.org/2001/XMLSchema-instance" rel="noopener noreferrer"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/a&gt;"&lt;br&gt;
         xsi:schemaLocation="&lt;a href="http://maven.apache.org/POM/4.0.0" rel="noopener noreferrer"&gt;http://maven.apache.org/POM/4.0.0&lt;/a&gt; &lt;a href="http://maven.apache.org/xsd/maven-4.0.0.xsd" rel="noopener noreferrer"&gt;http://maven.apache.org/xsd/maven-4.0.0.xsd&lt;/a&gt;"&amp;gt;&lt;br&gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;amp;lt;groupId&amp;amp;gt;org.example&amp;amp;lt;/groupId&amp;amp;gt;
&amp;amp;lt;artifactId&amp;amp;gt;LambdaTest&amp;amp;lt;/artifactId&amp;amp;gt;
&amp;amp;lt;version&amp;amp;gt;1.0-SNAPSHOT&amp;amp;lt;/version&amp;amp;gt;
&amp;amp;lt;dependencies&amp;amp;gt;
    &amp;amp;lt;dependency&amp;amp;gt;
        &amp;amp;lt;groupId&amp;amp;gt;org.Seleniumhq.Selenium&amp;amp;lt;/groupId&amp;amp;gt;
        &amp;amp;lt;artifactId&amp;amp;gt;Selenium-api&amp;amp;lt;/artifactId&amp;amp;gt;
        &amp;amp;lt;version&amp;amp;gt;4.0.0-alpha-7&amp;amp;lt;/version&amp;amp;gt;
    &amp;amp;lt;/dependency&amp;amp;gt;
    &amp;amp;lt;dependency&amp;amp;gt;
        &amp;amp;lt;groupId&amp;amp;gt;org.Seleniumhq.Selenium&amp;amp;lt;/groupId&amp;amp;gt;
        &amp;amp;lt;artifactId&amp;amp;gt;Selenium-remote-driver&amp;amp;lt;/artifactId&amp;amp;gt;
        &amp;amp;lt;version&amp;amp;gt;4.0.0-alpha-7&amp;amp;lt;/version&amp;amp;gt;
    &amp;amp;lt;/dependency&amp;amp;gt;
    &amp;amp;lt;dependency&amp;amp;gt;
        &amp;amp;lt;groupId&amp;amp;gt;org.Seleniumhq.Selenium&amp;amp;lt;/groupId&amp;amp;gt;
        &amp;amp;lt;artifactId&amp;amp;gt;Selenium-chrome-driver&amp;amp;lt;/artifactId&amp;amp;gt;
        &amp;amp;lt;version&amp;amp;gt;4.0.0-alpha-7&amp;amp;lt;/version&amp;amp;gt;
    &amp;amp;lt;/dependency&amp;amp;gt;
    &amp;amp;lt;dependency&amp;amp;gt;
        &amp;amp;lt;groupId&amp;amp;gt;org.testng&amp;amp;lt;/groupId&amp;amp;gt;
        &amp;amp;lt;artifactId&amp;amp;gt;testng&amp;amp;lt;/artifactId&amp;amp;gt;
        &amp;amp;lt;version&amp;amp;gt;6.14.3&amp;amp;lt;/version&amp;amp;gt;
    &amp;amp;lt;/dependency&amp;amp;gt;
    &amp;amp;lt;dependency&amp;amp;gt;
        &amp;amp;lt;groupId&amp;amp;gt;io.github.bonigarcia&amp;amp;lt;/groupId&amp;amp;gt;
        &amp;amp;lt;artifactId&amp;amp;gt;webdrivermanager&amp;amp;lt;/artifactId&amp;amp;gt;
        &amp;amp;lt;version&amp;amp;gt;4.4.3&amp;amp;lt;/version&amp;amp;gt;
    &amp;amp;lt;/dependency&amp;amp;gt;
&amp;amp;lt;/dependencies&amp;amp;gt;

&amp;amp;lt;properties&amp;amp;gt;
    &amp;amp;lt;maven.compiler.source&amp;amp;gt;8&amp;amp;lt;/maven.compiler.source&amp;amp;gt;
    &amp;amp;lt;maven.compiler.target&amp;amp;gt;8&amp;amp;lt;/maven.compiler.target&amp;amp;gt;
&amp;amp;lt;/properties&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&amp;lt;/project&amp;gt;&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Code Walkthrough&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this section on how to find element by text in Selenium, let us now check the test case walkthrough in detail. The BeforeTest and import statements remain the same as we saw in our previous example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;(findElementByPartialTextMatch)&lt;/strong&gt;: In this case, we are first logging into the Selenium Playground web page. After that, we locate all the Web Elements which have &lt;strong&gt;Table&lt;/strong&gt; in their text and store them in a list. Later, we iterate over the list and print their text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2524%2F1%2AU3SuJjrJc7otFKthzYe4Xg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2524%2F1%2AU3SuJjrJc7otFKthzYe4Xg.png" width="800" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tests are completed, you can also view your test results, logs, and the test recording as well in your &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A-FmKq2uEKX-0uA0pnQBMWA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2A-FmKq2uEKX-0uA0pnQBMWA.png" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also see the test results on the &lt;a href="https://analytics.lambdatest.com/test-overview?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The dashboard shows all the details and metrics related to your tests.&lt;/p&gt;

&lt;p&gt;Navigate to the LambdaTest Analytics Dashboard to view the metrics of your tests. You can quickly assess test performance and overall health from Test Overview. The Test Summary will show how many passed and failed tests your team has run and the overall efficiency of these tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxqZTMwVkSqwn4L1dYPeTyw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AxqZTMwVkSqwn4L1dYPeTyw.gif" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Console Output
&lt;/h2&gt;

&lt;p&gt;Once you run the test case, the console output will look something like the below:&lt;/p&gt;

&lt;p&gt;If you’re a developer or a tester and want to take your skills to the next level, this Selenium 101 certification from LambdaTest can help you reach that goal.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qx9FPFfJm7E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-java?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=apr05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Java tutorial&lt;/a&gt; on how to find element by text in Selenium WebDriver, we explored finding an element using text in Selenium. We saw how we could use the text() method in case of both complete and partial text matches. We also saw how we could use it in the case of FindElements and get a list of Web Elements through text match. In the end, we also implemented the cases using Selenium with Java on a cloud Selenium Grid.&lt;/p&gt;

&lt;p&gt;Honestly, using text() is one of my personal favorite methods in Selenium when it comes to locating Web Elements, as it’s very easy to implement and can be tweaked in any way to match our use case.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this article on how to find element by text in Selenium, learned some more about FindElement By Text, and I believe this method will become your personal favorite too. 🙂&lt;/p&gt;

&lt;p&gt;Happy Testing!!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>webdev</category>
      <category>css</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
