<?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>DEV Community: Veena devi</title>
    <description>The latest articles on DEV Community by Veena devi (@veenadevi12345).</description>
    <link>https://dev.to/veenadevi12345</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%2F1203960%2Fe460baee-6348-4e4e-a955-d3438cc579c5.png</url>
      <title>DEV Community: Veena devi</title>
      <link>https://dev.to/veenadevi12345</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/veenadevi12345"/>
    <language>en</language>
    <item>
      <title>Different Types Of Locators In Selenium WebDriver</title>
      <dc:creator>Veena devi</dc:creator>
      <pubDate>Thu, 09 Nov 2023 09:28:28 +0000</pubDate>
      <link>https://dev.to/testmuai/different-types-of-locators-in-selenium-webdriver-50f0</link>
      <guid>https://dev.to/testmuai/different-types-of-locators-in-selenium-webdriver-50f0</guid>
      <description>&lt;p&gt;Selenium is still the most sought-after framework when it comes to &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web automation testing&lt;/a&gt;. Though frameworks like Cypress, Puppeteer, PlayWright, etc., are playing the catch-up game, Selenium still rules the automation testing framework charts. As per my experience, every QA who wants to dabble with Selenium should have a good understanding of locators in Selenium WebDriver.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Minify your XML code with our efficient and reliable online free tool &lt;a href="https://www.lambdatest.com/free-online-tools/xml-minify?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;XML minify&lt;/a&gt; for better website performance. Get faster page load times and better results today. Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Playwright is an open-source, cross-browser automation framework that provides e2e testing without the need for any third-party tools. Learn what it is, how to install it, and how we can execute tests using Playwright.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/06HIhFcpBDo"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;a href="https://www.lambdatest.com/learning-hub/selenium-locators?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; can be considered as the building block of any type of Selenium automation test script. The reason is simple — locators in Selenium WebDriver help you in performing the requisite interactions with the elements in the DOM.&lt;/p&gt;

&lt;p&gt;Choosing the best-suited locators in Selenium WebDriver is one of the keys to ensuring that the tests are less flaky (or brittle) — a factor that leads to the failure of Selenium automation tests. Picture this — there is a huge test suite, and choosing inappropriate locators in Selenium WebDriver can lead to a breakdown of the entire test suite!&lt;/p&gt;

&lt;p&gt;Avoiding such a catastrophic situation when performing &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt; is essential, making it important to choose the right locator in Selenium WebDriver for interacting with the WebElements. In this Selenium testing tutorial, I deep dive into the multiple locators in Selenium WebDriver, along with demonstrating the usage of those locators. If you are a Selenium 4 user, make sure to check out the bonus section where I have covered relative locators in Selenium 4.&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=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  What are Locators in Selenium WebDriver?
&lt;/h2&gt;

&lt;p&gt;For starters, Selenium is a test automation framework that lets you automate the interactions with the WebElements on the DOM. Interactions (or actions) can be a click, type, double click, etc. For example, the &lt;a href="https://www.lambdatest.com/blog/what-is-actions-class-in-selenium/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Action class in Selenium&lt;/a&gt; provides appropriate methods to perform keyboard and mouse actions on the elements in the DOM.&lt;/p&gt;

&lt;p&gt;However, the first operation is to identify those WebElements on the document (or page) under test. This is where locators in Selenium WebDriver come into the picture.&lt;/p&gt;

&lt;p&gt;Locators in Selenium WebDriver provide mechanisms for identifying HTML elements on the page. &lt;a href="https://www.lambdatest.com/selenium?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; supports a number of different web locators, and you have to choose the one that meets your test requirements.&lt;/p&gt;

&lt;p&gt;Let’s consider a simple example where you need to devise a test scenario using Selenium where the email address has to be automatically entered in the text box “Your email address”.&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%2F0%2AbU7UE5nfvwP617i3.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%2F0%2AbU7UE5nfvwP617i3.png" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first task in your Selenium automation script is to identify the text box WebElement and later use the &lt;a href="https://www.lambdatest.com/blog/how-to-use-selenium-sendkeys/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;sendKeys method in Selenium&lt;/a&gt; for entering the email address. The identification of the WebElement (or HTML element) is made using locators in Selenium WebDriver.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tired of hard-to-read SQL code? Use our fast and reliable &lt;a href="https://www.lambdatest.com/free-online-tools/sql-beautifier?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;SQL Beautifier&lt;/a&gt; tool to format and beautify your SQL code, making it more structured and easy to read. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Selenium WebDriver provides the findElement() and findElements() method to locate the WebElements using the appropriate web locator. Shown below is an example of how to use locators in conjunction with findElement() [or findElements()] method when using Selenium Java for 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%2F2876%2F0%2ABG4w57GKS497_X5K.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%2F2876%2F0%2ABG4w57GKS497_X5K.png" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to locate WebElements in DOM
&lt;/h2&gt;

&lt;p&gt;Before any interaction can be performed on the WebElements in the DOM, the first task is to locate the elements in the DOM. Follow the below-mentioned steps to locate WebElements in the DOM (Document Object Model).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the target application and click on F12 or right-click and select inspect.&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%2F0%2ATL_y_lpJevT__TGk.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%2F0%2ATL_y_lpJevT__TGk.png" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A console window would open known Developer tools.&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%2F0%2AP7sl1cinVH7tj-XR.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%2F0%2AP7sl1cinVH7tj-XR.png" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is a mouse icon on the left-most side of the ‘Inspect Element’ tool. Once you hover over it, a message titled ‘Select an element in the page to inspect it’ will appear.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click on it and navigate to the element you wish to locate. Once you click on the element, the DOM would be highlighted for that element a 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%2F3200%2F0%2AieQwDBkVjjKS0HQe.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%2F0%2AieQwDBkVjjKS0HQe.png" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The selected row in the DOM is the context from where you want to fetch the values. For example, the highlighted DOM value is shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://accounts.lambdatest.com/dashboard" rel="noopener noreferrer"&gt;Dashboard&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you can choose the tagname, i.e., ‘a’ and link text, i.e., ‘Dashboard,’ to locate the desired element. The above technique will be used throughout my blog to demonstrate the usage of different locators in Selenium WebDriver.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Struggling with messy Lua scripts? Our &lt;a href="https://www.lambdatest.com/free-online-tools/lua-beautifier?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;Lua Beautifier&lt;/a&gt; tool provides clean and structured formatting. Beautify your code and Improve readability today! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Different types of Locators in Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Below is the list of these locators of Selenium WebDriver:&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;ClassName&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LinkText&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial LinkText&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TagName&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CssSelector&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XPath&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As mentioned earlier, &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; provides different web locators for locating WebElements on the page. Here are the different locators in Selenium WebDriver that I will be covering in-depth in the latter part of the 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%2F2000%2F1%2A_q_XeflfrZ8YyxYvZm0I3w.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_q_XeflfrZ8YyxYvZm0I3w.png" width="778" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using locators in Selenium 4 is a treat due to the introduction of &lt;a href="https://www.lambdatest.com/blog/selenium-4-relative-locator/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;relative locators in Selenium 4&lt;/a&gt;. The introduction of locators like above(), below(), toLeftOf(), toRightOf(), and near() makes it easy to locate WebElements in relation to a particular WebElement.&lt;/p&gt;

&lt;p&gt;This Selenium &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;WebDriver Tutorial&lt;/a&gt; for beginners and professionals will help you learn what’s new in Selenium 4 (Features and Improvements).&lt;/p&gt;
&lt;h2&gt;
  
  
  How to identify elements using Locators in Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;Now that I have covered the essentials of Selenium locators (including the additions in Selenium 4), let me deep-dive into each locator in Selenium WebDriver in more detail.&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;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Want to convert &lt;a href="https://www.lambdatest.com/free-online-tools/yaml-to-xml?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;YAML to XML&lt;/a&gt;? Save time and effort by converting your YAML files to XML with our free online tool. Fast, easy, and efficient. No signups required. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  ID Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID locator in Selenium&lt;/a&gt; is the most preferred and fastest way to locate desired WebElements on the page. ID Selenium locators are unique for each element in the DOM.&lt;/p&gt;

&lt;p&gt;Since IDs are unique for each element on the page, it is considered the fastest and safest method to locate elements. But unfortunately, developers may or may not follow this rule as browsers do allow bypassing this rule.&lt;/p&gt;

&lt;p&gt;Specifically, in the case of a table or list, the IDs may populate incrementally or dynamically depending upon the data in the table. In such cases, testers use other locators in Selenium WebDriver to locate the desired element on the page.&lt;/p&gt;

&lt;p&gt;One of the &lt;a href="https://www.lambdatest.com/blog/selenium-best-practices-for-web-testing/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium best practices&lt;/a&gt; is to leverage the capabilities offered by the ID locator in Selenium since it is the fastest locator of the entire lot. Therefore, choosing the ID locator over other locators in Selenium WebDriverwill go a long way to &lt;a href="https://www.lambdatest.com/blog/speed-up-selenium-test-cases-execution/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;speed up Selenium test case&lt;/a&gt; execution.&lt;/p&gt;

&lt;p&gt;Below is an example of the LambdaTest Login page showcasing how the ‘login’ field is being located via ID:&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%2F0%2AT1caXPWqdutsrLvb.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%2F0%2AT1caXPWqdutsrLvb.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have used the &lt;a href="https://www.lambdatest.com/blog/selectorshub-the-next-gen-xpath-css-selectors-tool/" rel="noopener noreferrer"&gt;SelectorsHub tool&lt;/a&gt; to locate the desired WebElement using the ID locator. Below is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input id="email" type="email" placeholder="Email" name="email" value="" required="required"
autofocus="autofocus" class="form-control " xpath="1"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The below method is used for locating the desired element using the ID locator:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.id("email"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If no element in the DOM matches with the required ID, NoSuchElementException is thrown. Therefore, it is important to have a good know-how of the common &lt;a href="https://www.lambdatest.com/blog/49-common-selenium-exceptions-automation-testing/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;exceptions in Selenium&lt;/a&gt; to build a more robust Selenium test suite.&lt;/p&gt;

&lt;p&gt;This certification is for anyone who wants to stay ahead among professionals who are growing their career in Selenium automation testing.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium 101 certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qx9FPFfJm7E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Need to convert &lt;a href="https://www.lambdatest.com/free-online-tools/xml-to-csv?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;XML to CSV&lt;/a&gt;? Simplify your data conversion process with our XML to CSV Converter tool. Convert your XML files to CSV format quickly and easily in seconds! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Name Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;An element can be defined via multiple attributes, one such attribute is Name. Name locator in Selenium WebDriver can also be used to locate elements like an ID locator.&lt;/p&gt;

&lt;p&gt;Unlike ID locators, which are unique for a page, the Name locator may or may not have a unique value. If there are WebElements with the same name, the locator selects the first element with that Name on the page.&lt;/p&gt;

&lt;p&gt;In case no such name matches with the defined attribute value, &lt;strong&gt;NoSuchElementException&lt;/strong&gt; is raised.&lt;/p&gt;

&lt;p&gt;To demonstrate the usage of the Name locator in Selenium WebDriver, we identify the same WebELement that was earlier located using the ID 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%2F3200%2F0%2AYw7oPwdZ7JVVOWFz.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%2F0%2AYw7oPwdZ7JVVOWFz.png" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input id="email" type="email" placeholder="Email" name="email" value="" required="required" autofocus="autofocus" class="form-control " xpath="1"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the desired WebElement was located using the Name locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.name("email"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  ‘Link Text’ Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;Elements can be located via link text that is present in the hyperlinks. For example, the first link would be selected in a scenario where there are multiple links of the same text.&lt;/p&gt;

&lt;p&gt;However, this Identifier strategy can only be used for elements that have an anchor(a) tag.&lt;/p&gt;

&lt;p&gt;Below is an example of Lambdatest homepage showcasing the selection of the ‘Automation’ link that is available on the header. The DOM below shows the highlighted element:&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%2F0%2A7A2KggX1b0OjT-n6.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%2F0%2A7A2KggX1b0OjT-n6.png" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the DOM structure of the same:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="https://www.lambdatest.com/automation-testing" class="desktop:block  desktop:ml-0 desktop:mt-10 nav-link inline-block py-5 text-size-14 font-medium ml-30 fromipad:ml-20 "&amp;gt;Automation&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the desired WebElement was located using the linkText locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.linkText("Automation"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Effortlessly convert SQL data to HTML tables with our feature-rich &lt;a href="https://www.lambdatest.com/free-online-tools/sql-to-html?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;SQL to HTML&lt;/a&gt; Converter. Streamline data representation and communicate insights effectively. Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Partial Link Text Locator In Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is a provision to locate a WebELement using Partial Link Text akin to the normal Link Text locator in Selenium. Locating WebElements using partial link text is preferred when the link text is too long.&lt;/p&gt;

&lt;p&gt;Here, the partial text helps identify a unique element and use it to perform further actions on it. Sometimes, using this can also be to locate multiple links on a page with a common partial text.&lt;/p&gt;

&lt;p&gt;Below is a snapshot of the LambdaTest DOM highlighting the element with the link name as ‘Start testing.’ Instead of using the complete link text, I use the partial link text locator to locate the element using the ‘testing’ 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%2F3200%2F0%2AgjbLAu6qr_aCVZSV.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%2F0%2AgjbLAu6qr_aCVZSV.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;a href="https://www.lambdatest.com/test-on-ios-devices"&amp;gt;Test on iOS Simulator&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the desired WebElement was located using the partial link text locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.name("email"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The syntax for locating element by partial link text is:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.partialLinkText ("Simulator"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;TagName Link Text Locator In Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As the name specifies, this &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS locator in Selenium&lt;/a&gt; WebDriver is used to identify elements using Tag names like div, table, h1, etc.&lt;/p&gt;

&lt;p&gt;The TagName locator is commonly used to identify all the links on a page and identify &lt;a href="https://www.lambdatest.com/blog/broken-links-testing-using-selenium/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;broken links 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%2F3200%2F0%2A6ju_RVeKFq3SA2tE.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%2F0%2A6ju_RVeKFq3SA2tE.png" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the syntax of locating all the links on the LambdaTest homepage:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; driver.findElements(By.tagName("a"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Get faster loading times and better user experience with our efficient &lt;a href="https://www.lambdatest.com/free-online-tools/json-stringify?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;JSON Stringify&lt;/a&gt; tool. Quickly compress your JSON data with ease and optimize your website now. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Watch this video to learn what the Actions Class is in Selenium and how to 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%2F0%2AF5tnjYXMFGg4Oc-Y.jpg" 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%2F0%2AF5tnjYXMFGg4Oc-Y.jpg" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ClassName Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;Class Name locator is used for locating WebElements that are defined using the class attribute. Shown below is the DOM snapshot of the LambdaTest login 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%2F3200%2F0%2AXtroIahgtqlBGXnu.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%2F0%2AXtroIahgtqlBGXnu.png" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For locating the ‘login’ element via the ClassName locator in Selenium, we use the class attribute in the following DOM structure:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button id="login-button" data-amplitude="" type="submit" class="btn btn-dark submit-btn" css="1"&amp;gt;Login&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the desired WebElement was located using the ClassName locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.className("submit-btn"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  XPath Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath locator in Selenium&lt;/a&gt; helps in locating elements on the web page using XML expressions. The basic syntax used for using XPath as a CSS locator in Selenium WebDriver is shown below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; XPath: //tagname[@attribute = 'value']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, &lt;a href="https://www.lambdatest.com/blog/locating-elements-by-tagname-in-selenium/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TagName in Selenium&lt;/a&gt; signifies the tag in the DOM structure that you are targeting to locate the desired WebElement. TagName can be input tag, anchor tag, etc.&lt;/p&gt;

&lt;p&gt;Attributes are defined via the prefix ‘@’ and their corresponding value. Thus, attributes like Name, ID, Class, etc., can be used along with TagName.&lt;/p&gt;

&lt;p&gt;XPath in Selenium can be used in multiple ways, as shown below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Standard XPath&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As the name indicates, this is the most basic (or standard) way of writing an XPath. To demonstrate the usage of a standard XPath locator in Selenium, let’s locate the email element on the LambdaTest homepage.&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%2F0%2AxzaO-hTksyG1TId6.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%2F0%2AxzaO-hTksyG1TId6.png" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="email" name="email" value="" placeholder="Email" required="required" autofocus="autofocus" class="form-control mt-3 form-control-lg"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The standard XPath of the desired WebElement is //input[&lt;a class="mentioned-user" href="https://dev.to/name"&gt;@name&lt;/a&gt;= ’email’]. Here is how the XPath is used with the findElement() method to locate the element.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//input[@name= ’email’]"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;XPath Contains&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;XPath similarly contains works like CSS selector ‘contains.’ It is extensively used on WebElements whose value is changing dynamically.&lt;/p&gt;

&lt;p&gt;Consider an example where the value of the login changes after appending the login text. Here, XPath contains will be super-helpful in locating the desired WebElement.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//tagname[contains(@attribute, ‘partial value of attribute’)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Below is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="text" placeholder="Full Name*" name="name" value="" class="form-control sign-up-input-2 "&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the desired WebElement was located using the ‘XPath contains’ locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//input[contains(@class, ‘form-control’)]"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Tired of manually creating JSON data? &lt;a href="https://www.lambdatest.com/free-online-tools/random-json-generator?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;random JSON Generator&lt;/a&gt;, Generate data in seconds which is easy-to-use tool. Try it now and make your development process a breeze! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  XPath using ‘AND’ &amp;amp; ‘OR’
&lt;/h3&gt;

&lt;p&gt;The ‘AND’ &amp;amp; ‘OR’ operators in the XPath selector in Selenium are used when locating a WebElement based on certain condition sets. In the case of ‘AND,’ both the conditions should be True. On the other hand, either of the two conditions can be true for ‘OR’ in operator XPath.&lt;/p&gt;

&lt;p&gt;Syntax of OR operator in XPath:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//input[@id='login_1' OR @name='login’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Syntax of AND operator in XPath:&lt;/p&gt;

&lt;p&gt;Let’s locate the email login element on the LambdaTest homepage using the ‘AND’ &amp;amp; ‘OR’ operators.&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%2F0%2AJB1uF7J3fWCq5YSs.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%2F0%2AJB1uF7J3fWCq5YSs.png" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="email" name="email" value="" placeholder="Email" required="required" autofocus="autofocus" class="form-control mt-3 form-control-lg"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how we used the OR operator with XPath locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//input[@type='email' OR @name='email']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how we used the AND operator with XPath locator in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//input[@type='email' AND @name='email']"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  starts-with() method in XPath
&lt;/h3&gt;

&lt;p&gt;The starts-with() method in XPath offers functionalities that are similar to the CSS Selector in Selenium. It helps in locating elements that start with a specified attribute value. The starts-with() method in XPath is majorly used for locating WebElements whose value changes on the refresh of a page.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//tagname[starts-with(@attribute,'starting name of the attribute value')]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the DOM structure for locating the Password field on the LambdaTest signup 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%2F3200%2F0%2A7EkGA4JoCk1aF1sS.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%2F0%2A7EkGA4JoCk1aF1sS.png" width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="password" placeholder="Desired Password*" name="password" class="form-control sign-up-input-2 "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how we locate the Password element using the starts-with() method with XPath in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//input[starts-with(@name,'pass')]"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;XPath Text&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Text in the XPath locator in Selenium helps in locating WebElements via XPath using exact text match. It can be used when elements have to be located by looking into the tags containing certain text.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//div[text()='Logged In']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To demonstrate XPath text usage, we locate the ‘FREE SIGN UP’ button on the &lt;a href="https://accounts.lambdatest.com/register?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest registration page&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%2F0%2Aj3L6a9UPfq8tmNZ5.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%2F0%2Aj3L6a9UPfq8tmNZ5.png" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the DOM structure of the required WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button class="btn btn-dark submit-btn g-recaptcha"&amp;gt;Free Sign Up&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how we locate the ‘FREE SIGN UP’ button element using the XPath text:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.xpath("//button[text()='Free Sign Up']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Both CSS Selector and XPath are useful when running complex Selenium test automation scenarios. Though I use XPath extensively, the choice between XPath and CSS Selector purely depends on the scenario complexity and your convenience in locating WebElements using the corresponding locator.&lt;/p&gt;

&lt;p&gt;When choosing, always look into the maintainability aspects of the locators, as that can make your job easier! Been there, done that by choosing the relevant locators in Selenium WebDriver when strategizing the Selenium automation testing strategy 🙂&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Need a quick placeholder image for your project? Use our online &lt;a href="https://www.lambdatest.com/free-online-tools/placeholder-image-generator?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;placeholder image generator&lt;/a&gt; tool that helps you generate customizable images for your projects. Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  CSS Selector Locator In Selenium
&lt;/h2&gt;

&lt;p&gt;CSS (Cascading Style Sheets) is used to style web pages. At the same time, CSS is also one of the widely-used ways to locate WebElements in the DOM.&lt;/p&gt;

&lt;p&gt;CSS Selector in Selenium should be opted if you cannot locate an element using ID or Name locators. It can be chosen over the XPath locator.&lt;/p&gt;

&lt;p&gt;Since multiple debates go around the corner for both of them, their usages for me depend on the complexity of the scenario. However, most people prefer using CSS selectors since those are faster than XPath.&lt;/p&gt;

&lt;p&gt;Here are the different ways in which QA engineers can make use of CSS Selectors in Selenium:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tag and ID in CSS Selector
&lt;/h3&gt;

&lt;p&gt;To locate elements by Tag and ID, you have to use the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Html tag&lt;/strong&gt;: It provides the tag we wish to locate (e.g. input tag).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;#&lt;/strong&gt;: It is used to represent the ID attribute. Keep in mind that when you wish to locate an element via ID through a CSS selector, it must have a hash sign on the same. For other attributes, we need not use the hash sig&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Value of the ID attribute&lt;/strong&gt;: This represents the value of the ID we are using to locate the element.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;css=(Html tag )(#) (value of the ID attribute)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Below is the DOM part indicating the login field of Makemytrip.com&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%2F0%2AUBONraH1bi9goDz8.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%2F0%2AUBONraH1bi9goDz8.png" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="password" name="password" placeholder="Desired Password*" required="required" id="userpassword" minlength="8" class="form-control " aria-autocomplete="list" xpath="1"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Need to protect your data? Our &lt;a href="https://www.lambdatest.com/free-online-tools/sha384-hash-calculator?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;SHA384 Hash Calculator&lt;/a&gt; creates secure, reliable, one-way hashes quickly and easily with just a few clicks. Try it out now! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here is how you can locate the required WebElement using the CSS Selector:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("input#userpassword"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Tag and Class in CSS Selector
&lt;/h3&gt;

&lt;p&gt;Apart from the syntax (or format) difference, the said locator is pretty much identical to the ID locator. A dot (.) is used when denoting the class attribute value rather than hash (#) in the case of class.&lt;/p&gt;

&lt;p&gt;Syntax&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;css=(HTML tag)(.)(Value of Class attribute)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Here is the DOM snapshot and the corresponding command to access the required WebElement using CSS Selector in Selenium:&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%2F0%2A6N22Dj6pb-ceRNR7.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%2F0%2A6N22Dj6pb-ceRNR7.png" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="text" placeholder="Full Name*" name="name" value="" required="required" class="form-control " xpath="1"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is how the Submit button is located using CSS Selector in Selenium&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("button.submit-btn"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Tag and Attribute
&lt;/h3&gt;

&lt;p&gt;The element can be located via tag name, and the corresponding attribute is defined using its value. In case multiple elements have the same tag and attribute, the first one will be selected.&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;css=(HTML Page)[Attribute=Value]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Here is the DOM structure:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="phone" placeholder="Phone*" name="phone" value="" class="form-control sign-up-input-2 "&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how the WebElement — ‘phone’ can be located using the CSS Selector in Selenium:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("input[name=\"phone\"]"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Tag, Class, and Attribute
&lt;/h3&gt;

&lt;p&gt;This locator is used with the class name and other attribute values.&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;css=(HTML tag&amp;gt;)(. )(Class attribute value)([attribute=Value of attribute])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s locate the ‘Free Sign Up’ button on the LamdaTest Signup 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%2F3200%2F0%2AT2iJzCGoIHk3KHOh.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%2F0%2AT2iJzCGoIHk3KHOh.png" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the DOM structure of the ‘FREE SIGN UP’ WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button data-sitekey="6LceAqQaAAAAAO0LcIgLnXy3gH_M3X5aDrqUihHw" data-callback="onSubmit" data-amplitude="R_sig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how you can locate the ‘FREE SIGN UP’ button the LambdaTest signup page:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("button.submit-btn[data-callback=\"onSubmit\"]"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This combination can also be implied on ID. The only difference is to use a hash (#) rather than a dot (.) when using an ID attribute and defining its ID value in place of the Class value.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Tired of manually replacing text? Use our online string &lt;a href="https://www.lambdatest.com/free-online-tools/find-and-replace-string?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;find and replace string&lt;/a&gt; tool lets you quickly search for and replace text in any document. Try it now! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Wild (*, ^ and $) in CSS for classes
&lt;/h3&gt;

&lt;p&gt;Selenium CSS selector in Selenium helps in matching multiple strings through the use of multiple patterns like ^, $, *. Wildcard selectors in CSS are used for selecting multiple elements simultaneously.&lt;/p&gt;

&lt;p&gt;Here are the ways in which wild cards can be effectively used with the CSS Selector in Selenium:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a. Starts-With in CSS Selector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Starts-With helps locate elements when we try to match elements with a string that starts with a designated value.&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;css=(HTML tag)([attribute^=start of the string])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Here is the DOM structure for locating the WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="email" name="email" value="" placeholder="Email" required="required" autofocus="autofocus" class="form-control mt-3 form-control-lg"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here how the CSS [attribute^=value] Selector is used for locating the desired WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("input[name^='em']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;b. Ends-With in CSS Selector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This helps locate elements when we try to match elements with a string that ends with a designated value.&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;css=(HTML tag)([attribute$=end of the string])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Here is the DOM structure of the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="email" name="email" value="" placeholder="Email" required="required" autofocus="autofocus" class="form-control mt-3 form-control-lg"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how Ends-With in CSS Selector is used for locating the required WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("input[name$='ail']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;c. Contains in CSS Selector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This helps locate elements when we try to match elements with a string containing a designated value.&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;css=(HTML tag)([attribute*=partial string])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Here is the DOM structure to locate the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="email" name="email" value="" placeholder="Email" required="required" autofocus="autofocus" class="form-control mt-3 form-control-lg"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how Contains in CSS Selector is used for locating the required WebElement:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("input[class*='control']"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;d. Child Elements in CSS Selector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the use of child elements, we can locate elements inside other elements. Child Elements in CSS Selector is particularly useful when trying to access data from a table, list of details, and more.&lt;/p&gt;

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

&lt;p&gt;For demonstrating the usage of Child Elements in CSS Selector, we locate a Child Element with reference to a particular element. The URL under test is the &lt;a href="https://www.lambdatest.com/blog?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest Blog&lt;/a&gt; link in the menu on the LambdaTest home 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%2F3200%2F0%2ApkmcP81U0oxHJ2SL.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%2F0%2ApkmcP81U0oxHJ2SL.png" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the DOM structure to locate the element:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul class="dropdown-menu resource-dropdown-menu &amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/blog/" class="inline-block &amp;gt;Blog&amp;lt;/a&amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/certifications/" class="inline-block &amp;gt;Certifications&amp;lt;/a&amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/learning-hub/" class="inline-block &amp;gt;Learning Hub&amp;lt;/a&amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/webinar/" class="inline-block &amp;gt;Webinars&amp;lt;/a&amp;gt;
        &amp;lt;a href="https://www.lambdatest.com/video/" class="inline-block &amp;gt;Videos&amp;lt;/a&amp;gt;
         &amp;lt;a href="https://www.lambdatest.com/newsletter/" class="inline-block &amp;gt;Newsletter&amp;lt;/a&amp;gt;
         &amp;lt;a href="https://community.lambdatest.com" class="inline-block&amp;gt;Community&amp;lt;/a&amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/customers/" class="inline-block&amp;gt;Case Studies&amp;lt;/a&amp;gt;
       &amp;lt;a href="https://www.lambdatest.com/blog/category/lambdatest-updates/" class="inline-block &amp;gt;Product Updates&amp;lt;/a&amp;gt;
      &amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In order to locate element, the following syntax would be used:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Css= tagname.class name li:nth-of-child(index of the referenced child which in our case is 3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how you can get the blog link from the page:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(By.cssSelector("ul.dropdown-menu a:nth-child(1)");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Similarly in order to access responsive we can use, last-child reference as below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Css= ul.dropdown-menu a
driver.findElement(By.cssSelector("ul.dropdown-menu a:last-child");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Blog on &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Selectors in Selenium Automation Scripts&lt;/a&gt; is a good resource to further drill down into the CSS Selectors in Selenium.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Relative Locators In Selenium WebDriver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;One of the major features of Selenium 4 is the introduction of relative locators. Relative locators in Selenium 4 help you search for WebElements in relation to the other elements.&lt;/p&gt;

&lt;p&gt;For example, using toLeftOf Selenium 4 relative locator, WebElements to the left of a certain element can be easily located. This results in a few findElement calls primarily used for locating elements on the page.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.lambdatest.com/blog/what-is-deprecated-in-selenium4/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;difference between Selenium 3 and Selenium 4&lt;/a&gt; is a good starting point to know the immense potential offered by the Selenium 4 framework. Here is a short gist of relative locators in Selenium 4:&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%2A0JgIsCG1x54Q2mjRc8Aujg.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%2A0JgIsCG1x54Q2mjRc8Aujg.png" width="792" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium 4 Learning Hub&lt;/a&gt; is the go-to resource to check what’s new in the Selenium 4 framework.&lt;/p&gt;

&lt;p&gt;To demonstrate the usage of relative locators in Selenium 4, we locate the WebElements on the &lt;a href="https://www.lambdatest.com/certifications/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Certifications&lt;/a&gt; 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%2F3200%2F0%2AS00J5a9xXm1D6je4.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%2F0%2AS00J5a9xXm1D6je4.png" width="800" height="594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first unique WebElement on the page is located using the following method:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement FirstElement = driver.findElement(By.Id("idvalue"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here is how below relative locator in Selenium 4 is used to locate the element below the Element we searched earlier:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;driver.findElement(with(By.tagName("tageName")).below(FirstElement));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The next set of WebElements on the page are identified using the above, below, toLeftOf, and toRightOf locators in Selenium 4:&lt;/p&gt;

&lt;p&gt;Here is the code snippet that showcases the usage of relative locators in Selenium 4:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement newCertification = driver.findElement(By.linkText("Cypress 101"));

WebElement findviaBelow = driver.findElement(with(By.tagName("h4")).below(newCertification));   
System.out.println("fetched via Below : "+findviaBelow.getText());

WebElement fetchviaToTheRight = driver.findElement(with(By.tagName("h4")).toRightOf(findviaBelow));

System.out.println("fetch via ToTheRight :"+fetchviaToTheRight.getText());

WebElement fetchviaabove = driver.findElement(with(By.tagName("h4")).above(fetchviaToTheRight));  
System.out.println("fetch via above : "+fetchviaabove.getText());

WebElement fetchviatoLeftOf=driver.findElement(with(By.tagName("h4")).toLeftOf(fetchviaabove));
System.out.println("fetched via toLeftOf :  "+fetchviatoLeftOf.getText());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Shown below is the console output:&lt;/p&gt;

&lt;p&gt;fetched via Below: Selenium C# 101&lt;br&gt;
fetch via ToTheRight: Selenium Java 101&lt;br&gt;
fetch via above: Selenium Python 101&lt;br&gt;
fetched via toLeftOf: Cypress 101&lt;/p&gt;

&lt;p&gt;You can also use a combination of relative locators to locate the desired WebElement.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WebElement fetchwithmutipleRelative=driver.findElement(with(By.tagName("h4")).below(fetchviatoLeftOf).toRightOf(fetchviaabove));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This code identifies an element, which is below a given WebElement and to the right of the newly searched element.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Say goodbye to manual coding errors with our &lt;a href="https://www.lambdatest.com/free-online-tools/html-escape?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools" rel="noopener noreferrer"&gt;HTML Escape&lt;/a&gt; tool to simplify HTML coding process. Escape special characters quickly — try it out today! Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Best practices for using Locators in Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;The main challenge in writing automation scripts lies in locating the right identifier for the target element. Following certain best practices will ensure that the team uses strategy efficiently to locate elements used in automation scripts.&lt;/p&gt;

&lt;p&gt;Following are some of the best practices for using locators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a unique ID for element identification&lt;/strong&gt;&lt;br&gt;
The first and main reason to use a unique ID is that it makes it simpler to identify a particular element. If you have two elements with the same ID, it becomes difficult to determine which element you want to use in your scripts. This may lead to issues such as selecting an incorrect element or a non-existent one. To avoid this, always assign a unique ID for each element you wish to utilize in your web application to avoid this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid using Ids that change locations&lt;/strong&gt;&lt;br&gt;
Selenium WebDriver locators depend on IDs because they match the ID attribute assigned by browsers, which is used as identifiers for each HTML tag on your page. The value of these IDs remains static as long as the browser window remains open. However, if you close and reopen the browser, these values change their position due to the fact that they now identify different objects on the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For example, if the locator is dependent on a single entity like class, name, id, etc., which, if changed, can be repaired but complex locators like By.XPath(“//div[&lt;a class="mentioned-user" href="https://dev.to/class"&gt;@class&lt;/a&gt;=”class-form_6180″]/div[5]/h3”) may lead to frequent breakage if any of the div or the class name changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, while using locators in Selenium WebDriver, do not locate elements that depend on auto-generated values. This is one of the key rules that one needs to keep in mind about locators in Selenium WebDriver for &lt;a href="https://www.lambdatest.com/blog/8-actionable-insights-to-write-better-automation-code/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;writing better automation code&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep your Locators short&lt;/strong&gt;&lt;br&gt;
Your locator should always identify the exact target element you want to click or locate and not other elements that are present on the same page. The benefit of this is that you’re reducing the chance of your script breaking because the number of elements on a page has changed (and thus, where they appear in the HTML code). Also, if your locator is short, it’s easier to see if it’s affecting more than one element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secondly, if you are trying to look out for multiple matches (using ‘findElements’), ensure it matches all the desired elements you are looking out for.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid elements that depend on auto-generated values&lt;/strong&gt;&lt;br&gt;
If you are using locators such as ID, CSS, and XPath, Selenium WebDriver provides a way to navigate to elements through the browser’s address bar. This is accomplished by using the locateElement() or locateElementBy*() methods. You can navigate to any element on the page by using the browser’s address bar and its locator parameters and values and this method. However, if you use IDs (e.g., “id=”tooltip””) as locators, it might not work quite as you expect. This is because IDs are auto-generated and do not always change when we expect them to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As a best practice, the first thing we should do is always use locators such as CSS and XPath instead of IDs as they never change their value. The second thing we should do is to watch those values after each run. So, if we want to locate an element with an ID of tooltip using the browser’s address bar, we should run and watch the values of those IDs to identify if they are auto-generated or not.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Don’t use XPath or CSS Selector provided by the Dev Tools&lt;/strong&gt;&lt;br&gt;
Choosing locators in Selenium is an important step, especially when you are new to it. There are many tips and tricks available on the web regarding this topic. But most of them suggest using XPath or CSS selectors provided by the browser’s dev tools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;However, if you use XPath or CSS Selectors provided by the browser’s dev tools, your tests will not work if the source code is changed. To have stable tests, you should use locators that are independent of HTML structure.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FwFDA0822T0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;With this, we come to the end of the tutorial on Selenium Locators. In this tutorial on locators in Selenium WebDriver, we first looked at different ways of locating WebElements in DOM. We also looked at different types of locators and relative locators used in Selenium and ways to locate elements using the id, name, class, and attribute selectors.&lt;/p&gt;

&lt;p&gt;Selenium locators can be used as a handy resource when you are performing Selenium automation testing. When it comes to Selenium automation testing, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; like LambdaTest offer the broadest set of cloud-based testing capabilities. With a single Selenium Grid node, you can access 3000+ browsers and operating systems for &lt;a href="https://www.lambdatest.com/?utm_source=medium&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_09&amp;amp;utm_term=vs&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;Now that you have learned how to use locators and relative locators in Selenium WebDriver, you should be able to work with locators effectively. I hope that this tutorial has helped you learn everything there is to know about using locators in the Selenium WebDriver.&lt;/p&gt;

</description>
      <category>selenium</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Selenium Standalone Server and Selenium Server [Differences]</title>
      <dc:creator>Veena devi</dc:creator>
      <pubDate>Wed, 08 Nov 2023 06:29:09 +0000</pubDate>
      <link>https://dev.to/veenadevi12345/selenium-standalone-server-and-selenium-server-differences-2cj0</link>
      <guid>https://dev.to/veenadevi12345/selenium-standalone-server-and-selenium-server-differences-2cj0</guid>
      <description>&lt;p&gt;A standalone server is a server that functions without the aid of a wider network, such as an enterprise-wide network, and offers services to clients. Selenium is unquestionably one 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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;best test automation frameworks&lt;/a&gt; for web &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;test automation&lt;/a&gt; out of the many that are currently on the market. Any programming language that enables the creation of tests, such as Java, Python, C#, JavaScript, Ruby, etc., is compatible with Selenium. For better test administration and orchestration, it may also be coupled with other automation testing frameworks like JUnit and TestNG. To get the most out of Selenium automated testing, knowledge of its components’ architecture, such as Selenium Standalone Server and Selenium Server, is crucial.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;**Protect your sensitive information with our &lt;a href="https://www.lambdatest.com/free-online-tools/hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;Hash Calculator&lt;/a&gt;. Create secure, one-way hashes in no time and keep your data safe from hackers. Try Now!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--76PrWqfI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2028/0%2AS6Suol1Nq7Fj22Pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--76PrWqfI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2028/0%2AS6Suol1Nq7Fj22Pm.png" alt="image" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Source&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This blog helps to understand the difference between Selenium Standalone Server and legacy Selenium Server in detail.&lt;/p&gt;

&lt;p&gt;Selenium Components&lt;/p&gt;

&lt;p&gt;Selenium is a suite of tools with a distinct approach to support automation testing. It provides more than just a base for building an automated testing framework — Selenium is an open-source project with a large community, which means there are many ways to contribute to the project, participate in the discussion and gain valuable knowledge.&lt;/p&gt;

&lt;p&gt;When writing this blog, Selenium has 22.6k Stars and 6.7k Forks on the Selenium GitHub Page. However, when integrating Selenium into your project, you need to consider that there are different ways of doing this. The latest version of Selenium (Selenium 4) has some interesting innovations. &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium 4&lt;/a&gt; was released in October 2020, with an exciting set of new features:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xx-lHhpj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A4SmjDncK81xsb9Xw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xx-lHhpj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A4SmjDncK81xsb9Xw.png" alt="image" width="533" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, if you are new to Selenium 4 or want to &lt;a href="https://www.lambdatest.com/blog/upgrade-from-selenium3-to-selenium4/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;migrate from Selenium 3 to Selenium 4&lt;/a&gt;, this video from the LambdaTest YouTube Channel will help you get started with Selenium 4:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5mmSISPUWUQ"&gt;
&lt;/iframe&gt;
&lt;br&gt;
You can follow the channel to stay updated with more videos on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Cypress Testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;Selenium has different components, which helps to achieve multiple purposes like Record and Playback test cases directly from the browser, running test cases in a remote machine, writing script-based test cases in various programming languages, and more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bCaELWJ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AIBj0WmLbONM9GMw_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bCaELWJ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AIBj0WmLbONM9GMw_.png" alt="image" width="512" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Make your data tamper-proof with our &lt;a href="https://www.lambdatest.com/free-online-tools/sha256-hash-calculator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;SHA256 Hash Calculator&lt;/a&gt;. Create secure, one-way hashes for your data in no time. Start creating your hashes now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Selenium IDE
&lt;/h2&gt;

&lt;p&gt;It’s an Integrated Development Environment to record and play AUT directly from the browser. Testers who don’t have scripting knowledge can effectively use this IDE to record their interactions with the AUT and playback any number of times in the future.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/support/docs/run-selenium-ide-tests-on-lambdatest-selenium-cloud-grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=support_doc"&gt;Selenium IDE &lt;/a&gt;is available as a browser extension, and it can only be used with browsers that support extensions. Initially, in Selenium 2, it was available only for the Chrome browser. However, now we can use it with Chrome, Firefox, and Edge browsers. With Selenium 4, the Selenium IDE can also be integrated with &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Selenium Cloud Grid&lt;/a&gt; like LambdaTest. This helps in expediting the testing process as Selenium automation tests can be run in parallel on different browsers &amp;amp; OS combinations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z1UAvHNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Akmda1in53xvz8agO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z1UAvHNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Akmda1in53xvz8agO.png" alt="image" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Selenium WebDriver
&lt;/h2&gt;

&lt;p&gt;&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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium WebDriver&lt;/a&gt; is an Open Source API and a script-based test framework that helps execute the same script in different browsers with the help of browser drivers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--39KPIz27--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AyCnxQC0nwTFobrkz7BfYNg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--39KPIz27--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AyCnxQC0nwTFobrkz7BfYNg.png" alt="image" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selenium WebDriver can be integrated with TestNG and JUnit test frameworks to achieve parallel execution, manage test scripts, and &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;generate test reports&lt;/a&gt;. To choose the appropriate framework for your test requirements, check out our tutorial on &lt;a href="https://www.lambdatest.com/blog/junit-5-vs-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;JUnit 5 vs. TestNG&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also perform &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Continuous Integration&lt;/a&gt; testing by &lt;a href="https://www.lambdatest.com/blog/build-and-execute-selenium-projects/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;integrating WebDriver with Maven&lt;/a&gt; and Continuous testing with Jenkins.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Use our fast and reliable &lt;a href="https://www.lambdatest.com/free-online-tools/ntlm-hash-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;NTLM hash generator&lt;/a&gt; online tool to generate high-quality secured unique NTLM hashes and protect your sensitive data from unauthorized access. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Selenium Grid
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/selenium-grid-setup-tutorial/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium Grid&lt;/a&gt; is a tool that allows you to manage several different Selenium Server instances on different machines. It makes the process of executing tests in parallel easier and allows you to scale your tests across a number of different nodes.&lt;/p&gt;

&lt;p&gt;Selenium Grid is most commonly used in automated web testing, however, it can be used for any type of test that requires multiple Selenium Server nodes.&lt;/p&gt;

&lt;p&gt;Let’s deep dive into Selenium Grid in the next section:&lt;/p&gt;
&lt;h2&gt;
  
  
  Selenium Standalone Server or Selenium Grid
&lt;/h2&gt;

&lt;p&gt;Selenium Grid facilitates test cases to execute in multiple machines and browsers simultaneously, which fastens the test case execution speed and drastically reduces the turnaround time. In Selenium 3, Selenium Standalone Server (Selenium Grid ) has two different components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium Hub&lt;/strong&gt;: Hub is a central system that accepts test case requests from clients. It also manages threads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selenium Node&lt;/strong&gt;: Node registers itself with the hub, and it’s a place where the actual browser exists. A node machine is connected to the hub, which receives test scripts from the hub and executes them. It is also possible to launch several nodes on different devices running different environments.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bF7EbNfF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AnL-RMUaLeWZddLMc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bF7EbNfF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AnL-RMUaLeWZddLMc.png" alt="image" width="548" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Selenium 4, the Grid becomes more flexible. For example, once the user starts the server, the Grid automatically works as both nodes and hubs, so the user does not need to start hub and node separately as in &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium 3 Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It also supports advanced tools like Docker, which is used in the DevOps process. Now Grid 4 has a more user-friendly UI also.&lt;/p&gt;

&lt;p&gt;There are three ways to run &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium Grid 4&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Starting as Standalone, Gird itself acts as hub and node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start as a separate Hub and Node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fully Distributed (Router, Session, Distributor, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also read: &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium Grid 4 Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Keep your data secure with our online &lt;a href="https://www.lambdatest.com/free-online-tools/shake256-hash-generator?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;SHAKE-256 Hash Generator&lt;/a&gt; tool that generates unique cryptographic hash functions for your data in just a few clicks. Try it today!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Executing Test Cases using Selenium Grid in Standalone mode
&lt;/h2&gt;

&lt;p&gt;In this section of the article, we will see how to execute test cases using Selenium Grid in Standalone mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step1:&lt;/strong&gt; Download Selenium Standalone Server/Grid jar file, i.e., selenium-server-4.1.1.jar&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jPBZmRJI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2AdrQJXcdiihxkobfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jPBZmRJI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2AdrQJXcdiihxkobfh.png" alt="image" width="800" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Start the server as Standalone. Open the terminal and navigate to where the jar file is downloaded, and then type:&lt;br&gt;
“java -jar selenium-server-4.1.1.jar standalone”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Now, the local Grid is ready with the attached node and starts to accept and execute test cases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dg7ieFnP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2268/0%2A5hoyjR0A_eUeqmph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dg7ieFnP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2268/0%2A5hoyjR0A_eUeqmph.png" alt="image" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the Server is started, all the available browsers and session details of browsers can be viewed at &lt;a href="http://localhost:4444/ui/index.html#/."&gt;http://localhost:4444/ui/index.html#/.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9bFCcPkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2A6XEK-q-cnNlKaiq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9bFCcPkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2A6XEK-q-cnNlKaiq5.png" alt="image" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: To execute test cases, initialize the browser from the grid and invoke via RemoteWebDriver, passing the grid URL and browser capability.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package LambdaTest;

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

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
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.Test;

public class TestCaseRunToGrid {

   public  RemoteWebDriver driver = null;


   @BeforeTest
   public void setUp() throws Exception {

       ChromeOptions options = new ChromeOptions();
        options.setAcceptInsecureCerts(true);
        options.setCapability(CapabilityType.BROWSER_NAME,"chrome");

       try {
         driver = new RemoteWebDriver(new URL("http://localhost:4444"), options);

       } 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 Selenium PlayGround page ");
           driver.get("https://www.lambdatest.com/selenium-playground/simple-form-demo");
           WebElement messageText=driver.findElement(By.cssSelector("input#user-message"));
           messageTextBox.sendKeys("Welcome to cloud grid");

           WebElement getValueButton = driver.findElement(By.cssSelector("#showInput"));
           getValueButton.click();
           System.out.println("Clicked on the Get Checked Value 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;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Tired of manually splitting long text strings? Try out our free online &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;String Split by Delimiter&lt;/a&gt; tool to quickly split text strings into separate chunks using any delimiter of your choice. Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2W43sVfv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2952/0%2AdPq3uC_RaGA-j_eD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2W43sVfv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2952/0%2AdPq3uC_RaGA-j_eD.png" alt="image" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this code block, I have used one of the most popular &lt;a href="https://www.lambdatest.com/blog/a-complete-guide-for-your-first-testng-automation-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;test automation frameworks, TestNG&lt;/a&gt;. TestNG is a java based framework designed for Unit, Functional, and End to End testing. If you are new to TestNG, you can go through this &lt;a href="https://www.lambdatest.com/learning-hub/testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=learning_hub"&gt;Selenium TestNG Tutorial&lt;/a&gt; to get started with your &lt;a href="https://www.lambdatest.com/blog/a-complete-guide-for-your-first-testng-automation-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;first TestNG automation script&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://www.lambdatest.com/blog/asserts-in-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;TestNG Assertions&lt;/a&gt; and Annotations, you can &lt;a href="https://www.lambdatest.com/blog/grouping-test-cases-in-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;group and orchestrate&lt;/a&gt; the large test case execution, validate the expected result, and execute test cases in parallel.&lt;/p&gt;

&lt;p&gt;@BeforeTest is the &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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;TestNG Annotation&lt;/a&gt; that executes the statements before each TestMethod runs. Prerequisites for each test method like launching the browser, configuring browser parameters, launching the application URL, setting browser properties kind of statements can be included in this code block.&lt;/p&gt;

&lt;p&gt;In Selenium 3, DesiredCapabilities Class helps to set up properties of the browser. However, the DesiredCapabilities Class is replaced by Options in Selenium 4.&lt;/p&gt;

&lt;p&gt;Each browser has a respective Option Class that provides methods to change the browser’s properties such as cookies, incognito, headless, disabling pop-ups, and adding extensions.&lt;/p&gt;

&lt;p&gt;Here is the Options object that would be used for setting 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;Internet Explorer (IE) — InternetExplorerOptions&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;Microsoft Edge — EdgeOptions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RemoteWedDriver is a Class with all driver classes like ChromeDriver, EdgeDriver, FirefoxDriver, InternetExplorerDriver, OperaDriver, SafariDriver as SubClass.&lt;/p&gt;

&lt;p&gt;To use this Class, we have to import the “org.openqa.selenium.remote” package.&lt;br&gt;
The RemoteWebDriver accepts two parameters, one is the hub URL, and the other one is an object of Browser Option. Here, I have launched Chrome browser using ChromeOption object, which provides the property of the browser to launch.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Convert your &lt;a href="https://www.lambdatest.com/free-online-tools/text-lowercase?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;text to lowercase&lt;/a&gt; with our reliable and easy-to-use online tool. Get started now and save time on editing. Try it for free.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WRJXegVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3144/0%2AvrsNboZLRuL8VLCH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WRJXegVf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3144/0%2AvrsNboZLRuL8VLCH.png" alt="image" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; Annotation is one of the most important TestNG Annotations, which drives a simple Java method as a test case.&lt;/p&gt;

&lt;p&gt;WebElement is a Selenium class, where the driver.findElement returns a WebElement object. Here, the Elements can be identified using multiple locator strategies.&lt;/p&gt;

&lt;p&gt;&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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;Selenium Locators&lt;/a&gt; makes it easy to locate elements on a webpage and perform actions on them, which helps to ease the process of Selenium Automation Testing.&lt;/p&gt;
&lt;h3&gt;
  
  
  Advantages of Selenium Standalone Server
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Helps to handle test execution in the distributed way either in VM or &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helps to perform &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;cross browser test automation&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can achieve &lt;a href="https://www.lambdatest.com/blog/parallel-test-execution-in-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=blog"&gt;parallel execution&lt;/a&gt; using Selenium Cloud Grid, where you can execute multiple test cases in parallel in different environments.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Limitations of working on local Selenium Grid
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Initial setup of various nodes in different OS, browser, browser versions and setting up devices for mobile testing is burdensome for the QA team. It requires skilled resources to set up Hub and Node in various environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The performance also wholly depends on the Server/VM used to set up nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s tough to scale down or up the number of nodes on demand.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Selenium Cloud Grid is the best solution to overcome all these shortcomings of the local grid.&lt;/p&gt;

&lt;p&gt;Watch this video to learn about collecting performance metrics in Selenium 4 using the Chrome DevTools Protocol on the LambdaTest platform.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/w7xkMk-0Yg0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Get faster loading times and better user experience with our efficient &lt;a href="https://www.lambdatest.com/free-online-tools/json-minify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;JSON minify&lt;/a&gt; tool. Quickly compress your JSON data with ease and optimize your website now. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Why do we need Selenium Cloud Grid?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Easy maintenance — the team doesn’t need to take any hassle to maintain the software or hardware needs of servers for node setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scalability — easy to manage the number of nodes/parallel execution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reliability — Cloud servers have near-perfect availability, so there is a low risk of interruption.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Executing Test Cases using cloud Selenium Grid
&lt;/h2&gt;

&lt;p&gt;This needs a minor update on code snippets, where the localhost gets to communicate with &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Selenium Cloud Grid&lt;/a&gt; like LambdaTest and access the URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Register on LambdaTest&lt;/a&gt; and get the Username and Access Key from the &lt;a href="https://accounts.lambdatest.com/detail/profile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;LambdaTest Profile Section&lt;/a&gt;.&lt;/p&gt;

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

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.CapabilityType;
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.Test;

public class TestCaseRunToCloudGrid {

   public  RemoteWebDriver driver = null;

   public String username = "";//LambdaTest userName
   public String accesskey = "";//LambdaTest Accesskey
   public String gridURL = "@hub.lambdatest.com/wd/hub";

   @BeforeTest
   public void setUp() throws Exception {

   DesiredCapabilities capabilities = new DesiredCapabilities();
   capabilities.setCapability("browserName", "Chrome");
   capabilities.setCapability("browserVersion", "97.0");
   HashMap&amp;lt;String, Object&amp;gt; ltOptions = new HashMap&amp;lt;String, Object&amp;gt;();
   ltOptions.put("user",username);
   ltOptions.put("accessKey",accesskey);
   ltOptions.put("build", "Selenium 4 grid Sample");
   ltOptions.put("name", "Selenium 4 grid Sample");
   ltOptions.put("platformName", "Windows 11");
   ltOptions.put("selenium_version","4.0.0");
   capabilities.setCapability("LT:Options", ltOptions);
       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 Selenium PlayGround page ");
           driver.get("https://www.lambdatest.com/selenium-playground/simple-form-demo");
           WebElement messageTextBox = driver.findElement(By.cssSelector("input#user-message"));
           messageTextBox.sendKeys("Welcome to cloud grid");

           WebElement getValueButton = driver.findElement(By.cssSelector("#showInput"));
           getValueButton.click();
           System.out.println("Clicked on the Get Checked Value 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;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Minify your JS code with &lt;a href="https://www.lambdatest.com/free-online-tools/js-minify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;JS Minify&lt;/a&gt; without changing its functionality with our easy-to-use JavaScript Minifier that reduces the size of your scripts and improve website speed. Try Now!&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SRsOcVz5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2144/0%2AHYvsrBlsZ4OIIfCr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRsOcVz5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2144/0%2AHYvsrBlsZ4OIIfCr.png" alt="image" width="800" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These public variables store the values for the LambdaTest username, key, and hub URL to execute the test case in Cloud Grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m_-M3g5M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Afy6xuGene-EUVGvW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m_-M3g5M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Afy6xuGene-EUVGvW.png" alt="image" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How the cloud grid understands the browser properties needs to be changed to scale up from local Grid to Selenium Cloud Grid. Here, only the hub URL and capabilities need to be updated by generating capabilities from &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;LambdaTest Capability Generator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Selenium testing tools like LambdaTest allows you to perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;cross browser testing&lt;/a&gt; at scale. &lt;a href="https://www.lambdatest.com/list-of-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;list of browsers&lt;/a&gt; provides 3000+ browsers with a combination of different OS and versions. The ltOptions map here stores all the browser properties required to launch the browser from the cloud hub.&lt;/p&gt;

&lt;p&gt;RemoteWebDriver accepts two parameters, one as a Hub URL with credentials and the second one as a Capability object which has all the properties about the browser to launch. Here it is Windows 11 OS, Chrome Browser version 97.0.&lt;/p&gt;

&lt;p&gt;Once the code is executed, 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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;LambdaTest Automation Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hXohz1f9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2A38Jcnk9n2LaGIsOe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hXohz1f9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2A38Jcnk9n2LaGIsOe.png" alt="image" width="800" height="386"&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=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;LambdaTest Analytics Dashboard&lt;/a&gt;. The dashboard shows all the details and metrics related to your tests under the Test Overview and Test Summary section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pCdcfe-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AtaHNLgjjlBI1e9MJ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pCdcfe-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AtaHNLgjjlBI1e9MJ.gif" alt="image" width="600" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re a software developer or tester with an interest in Selenium automation testing, this Selenium 101 certification course can help you develop your skillset.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium 101 certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qx9FPFfJm7E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium Server
&lt;/h2&gt;

&lt;p&gt;The Selenium server in Selenium 2 is entirely different from what we call Selenium Standalone Server/&lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=webpage"&gt;Selenium Grid&lt;/a&gt; in Selenium 4 and Selenium 3.&lt;/p&gt;

&lt;p&gt;Selenium Remote Control (RC) was the main Selenium project that stood for a long time before Selenium WebDriver(Selenium 2.0) came into existence. But unfortunately, it depreciated due to its complex JavaScript layers and redundant API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selenium RC components
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Client libraries for scripting language binding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium Server to launch and interact with the browser&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--neTMliAx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2Acpu6jUyPVvy0WHE7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--neTMliAx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2Acpu6jUyPVvy0WHE7.png" alt="image" width="533" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selenium server helps to execute Selenium RemoteControl client scripts. Now it’s completely deprecated, and we don’t have the option to download this jar itself.&lt;br&gt;
However, when we look into older versions to better understand, To execute RemoteControl scripts, we need to start the Selenium Server first.&lt;/p&gt;

&lt;p&gt;Here, I have mentioned a RemoteControl script, which executes the code in the local Selenium server, using LocalHost.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TTHNYPIZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2744/0%2AQZ2ScWbLoTPcf4xi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TTHNYPIZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2744/0%2AQZ2ScWbLoTPcf4xi.png" alt="image" width="800" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Minimize the file size of your CSS files for faster loading web pages with our free online &lt;a href="https://www.lambdatest.com/free-online-tools/css-minify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov_08&amp;amp;utm_term=vs&amp;amp;utm_content=free_online_tools"&gt;CSS Minify&lt;/a&gt; tool. Easy and efficient minification in just a few clicks. Try Now! *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Difference Between Selenium Standalone Server and Selenium Server
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7G7OVfOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ar6jbEiqtQAWa5ia4QgHmPQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7G7OVfOP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ar6jbEiqtQAWa5ia4QgHmPQ.png" alt="image" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this article, we have seen the difference between Selenium Standalone Server and Selenium Server. Understanding the difference between Selenium Standalone server and Legacy Selenium Server helps use the Selenium Grid effectively either in local, distributed mode or in Cloud Selenium Grid.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
