<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Solomon Eseme</title>
    <description>The latest articles on Forem by Solomon Eseme (@solomoneseme).</description>
    <link>https://forem.com/solomoneseme</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%2F978359%2F312f7dcd-57b8-448d-8b9b-b35c13c43368.jpeg</url>
      <title>Forem: Solomon Eseme</title>
      <link>https://forem.com/solomoneseme</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/solomoneseme"/>
    <language>en</language>
    <item>
      <title>How To Reduce Page Load Time In JavaScript</title>
      <dc:creator>Solomon Eseme</dc:creator>
      <pubDate>Mon, 10 Jul 2023 12:13:32 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-reduce-page-load-time-in-javascript-2gfm</link>
      <guid>https://forem.com/testmuai/how-to-reduce-page-load-time-in-javascript-2gfm</guid>
      <description>&lt;p&gt;Page speed is a significant challenge in modern web applications. It is an important part of any user’s experience.&lt;/p&gt;

&lt;p&gt;According to Forbes, 40% of people bounce from a website that takes more than 3 seconds to load. It is also important to note that a website that achiеvеs a loading timе of just 1 sеcond еxpеriеncеs a convеrsion ratе 5x highеr comparеd to a wеbsitе that takеs 10 sеconds to load.&lt;/p&gt;

&lt;p&gt;This shows that users care more about page speed than the new shining design added to the website. To understand how your users will interact with your web pages, you need to further &lt;a href="https://www.lambdatest.com/blog/test-mobile-websites-on-different-network-conditions/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test websites under different network conditions&lt;/a&gt;, different screen sizes, browsers, and platforms.&lt;/p&gt;

&lt;p&gt;This information will expose how users will interact with your webpage, and it will also show the UI components that need improvement even before moving your webpage to the production environment.&lt;/p&gt;

&lt;p&gt;This blog will explore how to reduce page load time in JavaScript and the tips you can implement to increase your page speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Page Load Time?
&lt;/h2&gt;

&lt;p&gt;Page load time is the average time it takes for a page to appear on your screen. It is calculated from when the page link is clicked or loaded to when it is completed. In enterprise applications, reducing the amount of time it takes for a page to load is an important investment, as we have seen in examples of how it could minimize conversion rate and affect business revenue.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Here’s 295+ &lt;a href="https://www.lambdatest.com/learning-hub/selenium-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium Interview Questions&lt;/a&gt; with Answers that will help you boost your confidence in an Interview. *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why Reduce Page Load Time in JavaScript?
&lt;/h2&gt;

&lt;p&gt;As we have discussed above, there are financial and other implications, such as a drop in traffic, drop in conversions, or increased bounce rate, etc., for not reducing the page load time. Below are some benefits why you should reduce the page load time of your software application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improve user experience:&lt;/strong&gt; Faster page loading times lead to improved user experience, as users can find the information they need quickly and easily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increase conversion rates:&lt;/strong&gt; When users can load a page quickly, they are more likely to stay on the page and complete the desired action.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improve SEO rankings:&lt;/strong&gt; From Search Engine Journals, search engine algorithms take page loading times into account when ranking websites, so faster page loading times can help improve SEO rankings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduce server load:&lt;/strong&gt; Faster page loading times can reduce the load on the server, leading to improved performance and reliability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduce bounce rates:&lt;/strong&gt; Faster page loading times can reduce bounce rates, as users are more likely to stay.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a website takes a long time to load, users may be quick to abandon it and switch to a faster-performing one. On the other hand, a website with a fast loading speed will give the impression of being user-friendly and appealing, thus increasing the potential for more website traffic.&lt;/p&gt;

&lt;p&gt;People who come to the website would likely enjoy looking at other content as well. The more people who look at the website’s content, the lower the bounce rate will be. The bounce rate is the percentage of people who leave the website after viewing only one page. The lower the bounce rate, the higher the quality of the website, both in terms of content and performance.&lt;/p&gt;

&lt;p&gt;In the next section of this tutorial on how to reduce page load time in JavaScript, we will explore the different strategies you can implement to reduce the page load time of your software application.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Reduce Page Load Time in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Different strategies can be used to reduce page load time. In this section on how to reduce page load time in JavaScript, we will elucidate some strategies you can use to reduce page load time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Minimize HTTP Requests
&lt;/h2&gt;

&lt;p&gt;One of the major causes of slow page load time is the number of HTTP requests the page has to complete before painting the page to the screen.&lt;/p&gt;

&lt;p&gt;The larger the number of requests, the more the page loads slowly, especially if the requests contain large data to load, such as large images, videos, or HTTP payloads.&lt;/p&gt;

&lt;p&gt;Therefore, to reduce your page load time, you need to inspect the different HTTP requests and the number of these requests your page is loading and reduce it.&lt;/p&gt;

&lt;p&gt;The most effective way to reduce the number of requests is to combine all JavaScript resources into one, and you can do that with different applications, libraries, and online tools. However, we will demonstrate how to automate the building process using Apache Ant.&lt;/p&gt;

&lt;p&gt;In Ant, the concat task can be used to join multiple files together. It is important to remember that the JavaScript files must be combined in the correct order to ensure that any dependencies are respected. To specify the order in which the files should be combined, you can use either a filelist or a combination of fileset elements.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;If you are preparing for a Playwright automation interview, this list of &lt;a href="https://www.lambdatest.com/learning-hub/playwright-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Playwright interview questions&lt;/a&gt; can help you get a list of the most asked questions with detailed answers. *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here is an example of how this could be done.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;target name="js.concatenate"&amp;gt;
    &amp;lt;concat destfile="${bld.dir}/result.js"&amp;gt;
    &amp;lt;filelist dir="${src.dir}"
        files="script1.js, script2.js"/&amp;gt;
    &amp;lt;fileset dir="${src.dir}"
        includes=".js"
        excludes="script1.js, script2.js"/&amp;gt;
    &amp;lt;/concat&amp;gt;
&amp;lt;/target&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Ant is instructed by this code to generate a file called result.js in the build directory. The contents of this file will be the combination of script1.js, then script2.js, and then all the files in the src directory in alphabetical order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable Compression
&lt;/h2&gt;

&lt;p&gt;You can use HTTP transfer encodings such as brotli or gzip to compress JavaScript assets in transmission when you enable compression in your request and response to the live cycle.&lt;/p&gt;

&lt;p&gt;This process allows efficient transmission of files and therefore results in a faster page load time. Generally, the compression ratio can reach 75%, that is, KB; the compression size is only 25 kB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using a Content Delivery Network
&lt;/h2&gt;

&lt;p&gt;Content Delivery Network (CDN) is a great way to reduce the latency of your users and deliver content to them faster because the content will be served from a location closer to them.&lt;/p&gt;

&lt;p&gt;In addition, distributing static assets with a Content Delivery Network (CDN) can serve website visitors from a place closer to them geographically and also cache the content for the user during revisit.&lt;/p&gt;

&lt;p&gt;Below are some of the CDN you can choose from to host your static files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Akamai&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cloudflare&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon CloudFront&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Microsoft Azure CDN&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Cloud CDN&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fastly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Level 3&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Limelight Networks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CacheFly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;EdgeCast&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Here’s Top 30+ &lt;a href="https://www.lambdatest.com/learning-hub/webdriverio-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;WebdriverIO Interview Questions&lt;/a&gt; and Answers that will help you boost your confidence in an Interview. *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Minify Resources
&lt;/h2&gt;

&lt;p&gt;Minifying resources is another important strategy used to reduce the code size of your application without compromising any of its functionality. You can use different modification tools to minify the code, such as Closure Compiler, JSMin, or Uglify.&lt;/p&gt;

&lt;p&gt;To minify a large JavaScript file on the go, you can install the uglify library globally using the command below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install uglify-js -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here’s a screenshot of a successful installation.&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%2Az75bl28WwwOq2C8g.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%2F0%2Az75bl28WwwOq2C8g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you can use this command below to minify your JavaScript files as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uglifyjs jquery-3.2.1.js — output jquery-3.2.1.min.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ARDOGqEnRK0VIXFvD.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%2F0%2ARDOGqEnRK0VIXFvD.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The original file size before minifying with the Uglify library.&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%2A4ZTAkHMpfmpPIZ0q.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%2F0%2A4ZTAkHMpfmpPIZ0q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The current file size after minifying with the Uglify library. UglifyJS default settings determine the name of the input file and the output file. Already, there is a significant decrease in size; the original file was 268 KB, but after running it through UglifyJS, it is now only 136 KB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimize Images
&lt;/h2&gt;

&lt;p&gt;With more than 3.2 billion photos uploaded to the Internet daily, according to Photodoto, it is clear that images occupy the majority of your web content and, therefore, should be properly optimized to improve the load time of your web pages.&lt;/p&gt;

&lt;p&gt;You can optimize your images in different ways. However, below are some other ways you can optimize your web images.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the correct file format:&lt;/strong&gt; JPEG for photographs, PNG for graphics and illustrations, and GIF for simple graphics and animations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resize images to the correct dimensions:&lt;/strong&gt; The larger the image, the more data it contains and the longer it takes to load.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compress images:&lt;/strong&gt; Compressing images reduces the file size without sacrificing quality. Tools like TinyPNG let you reduce the size of images without losing their quality. &lt;br&gt;
Also, to customize the size of the image with &lt;a href="https://www.lambdatest.com/blog/responsive-css-media-queries-for-responsive-design/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS and media queries&lt;/a&gt;, it is recommended to use a tool to reduce the image rather than doing it in real time with CSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a content delivery network (CDN):&lt;/strong&gt; A CDN is a server network that delivers images to users based on their geographic location.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reduce Redirects
&lt;/h2&gt;

&lt;p&gt;Reducing redirects on a web page can reduce page load time by eliminating the extra time it takes for the browser to make multiple requests to the server.&lt;/p&gt;

&lt;p&gt;When a browser requests a page, it must first request the server, then wait for a response. If the response from the server is to redirect to another website, the browser must then make another request to the new page and wait for a response.&lt;/p&gt;

&lt;p&gt;This process takes time, and if there are multiple redirects, the page load time can be significantly increased. By reducing redirects, the browser can make fewer requests and receive responses faster, resulting in a faster page load time.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*&lt;em&gt;Prepare to ace your interviews with our thorough set of &lt;a href="https://www.lambdatest.com/learning-hub/jest-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Jest interview questions&lt;/a&gt; and solutions that will enable you to prove your command of the Jest testing framework. *&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Leverage Browser Caching
&lt;/h2&gt;

&lt;p&gt;Leveraging browser caching is a technique used to reduce page load time by allowing the browser to store certain web page resources locally.&lt;/p&gt;

&lt;p&gt;When a user visits a website, the browser will download the resources needed to render the page, such as images, CSS, and JavaScript.&lt;/p&gt;

&lt;p&gt;By leveraging browser caching, the browser will store these resources locally. When the user revisits the same page, the browser will not have to download the resources again, thus reducing the page load time.&lt;/p&gt;

&lt;p&gt;For example, the browser will fetch the HTML page from the web server but consult its cache for static assets (JavaScript, CSS, images) and return the content of the cache if found. If not, it will return the server’s content.&lt;/p&gt;

&lt;p&gt;Here’s an image that illustrates the concept of browser caching.&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%2AjhtupCO6hpRWbMrg.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%2AjhtupCO6hpRWbMrg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The importance of browser caching is that it reduces the amount of data that is returned from the server, thereby making the request respond faster.&lt;/p&gt;

&lt;p&gt;You can look at the example of a website with Caching and No Caching to see the amount of data transferred.&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%2AKYtQMSDdUrQi7QLC.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%2F0%2AKYtQMSDdUrQi7QLC.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without caching, we notice a very high amount of data transferred from the server to the browser causing the web page to slow a little.&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%2Ak9pJx2FFacgK5lQm.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%2F0%2Ak9pJx2FFacgK5lQm.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above image shows that the load time has drastically reduced because of browser caching by reducing the amount of data that is loaded from the server rather than the cached data.&lt;/p&gt;

&lt;p&gt;In Chrome, you can view the contents of the cache. This will display a page of links to a detailed view of each cached file.&lt;/p&gt;

&lt;p&gt;In the next section of this tutorial on how to reduce page load time in JavaScript, we will explore how to test website speed on different devices. In addition, we will indicate some pointers to help you improve your website page speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Testing Websites for Speed Optimization
&lt;/h2&gt;

&lt;p&gt;In this section on how to reduce page load time in JavaScript, we will explore the role of &lt;a href="https://www.lambdatest.com/blog/website-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;website testing&lt;/a&gt; for page speed optimization.&lt;/p&gt;

&lt;p&gt;Developing websites is not easy and requires a lot of effort from the development teams; however, what use is a website that does not solve a user’s problem and generates revenue as fast as possible? This makes developers expend effort and time optimizing slow and unfriendly websites, making it a top priority if the website is slow and losing users.&lt;/p&gt;

&lt;p&gt;Nevertheless, developers need a way to test the speed of a website before deploying to production, or instead of waiting for the traffic to fall and users to start losing interest because of the speed problems, using a tool to test the website before deploying is an ideal solution.&lt;/p&gt;

&lt;p&gt;However, it is general knowledge that a website can behave in a certain manner depending on the network, geo-location, or device because of the device configurations. Therefore, if you want to see real results, you need to test your website with a tool that uses real devices.&lt;/p&gt;

&lt;p&gt;Several tools are available at your disposal to test the speed of your website.&lt;/p&gt;

&lt;p&gt;In this tutorial on how to reduce page load time in JavaScript, we will use Google PageSpeed and a mobile-friendly tester tool by LambdaTest called LT Browser 2.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Google PageSpeed
&lt;/h2&gt;

&lt;p&gt;Google PageSpeed allows you to test the speed of your website for both desktop and mobile devices. It gives you the overall percentages and lists all the issues that need to be fixed.&lt;/p&gt;

&lt;p&gt;Visit Google PageSpeed, type in the website URL you want to test, and wait for the results to appear.&lt;/p&gt;

&lt;p&gt;In this example, we are checking the performance of the LambdaTest website, and below are the results and some of the&lt;br&gt;
issues we can fix to improve the performance and usability of the website. In this image below, you can experience how your users are experiencing and how the pages of your website are being delivered to them.&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%2AgkyG4S539PXZp3EI.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%2F0%2AgkyG4S539PXZp3EI.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will look at the “Diagnose performance issues” and the percentages for each category.&lt;/p&gt;

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

&lt;p&gt;From the screenshot above, we can see a 97% performance, with all the metrics that &lt;a href="https://www.lambdatest.com/blog/how-to-measure-page-load-times-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;optimize page load time&lt;/a&gt;. These metrics are part of the &lt;a href="https://www.lambdatest.com/blog/core-web-vitals-expert-tips-to-improve-website-performance/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Core Web Vitals&lt;/a&gt;, and Core Web Vitals are specific factors that Google considers important in a webpage’s overall user experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First content paint:&lt;/strong&gt; This indicatеs thе momеnt whеn thе first tеxt or imagе is displayеd on thе pagе.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Speed index:&lt;/strong&gt; Thе spееd indеx mеasurеs thе spееd at which thе pagе’s contеnt bеcomеs visiblе to usеrs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Largest contentful paint:&lt;/strong&gt; Thе largеst contеntful paint rеprеsеnts thе point in timе whеn thе large tеxt or imagе is rеndеrеd on thе pagе.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time to interactive:&lt;/strong&gt; It rеfеrs to thе duration rеquirеd for thе pagе to bеcomе fully intеractivе.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total blocking time:&lt;/strong&gt; Sum of all time periods between First Content Paint (FCP) and Time to Interactive (TTI) when task length exceeds 50ms, expressed in milliseconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cumulative Layout Shift:&lt;/strong&gt; This measures the movement of visible elements within the viewport.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These metrics and more are the ways your website performance and speed are measured. In addition, Google PageSpeed also lists suggestions on how you can further improve your page speed and performance, amongst other diagnoses.&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%2F2064%2F0%2AQYwVCYvDXsDJwCX8.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%2F2064%2F0%2AQYwVCYvDXsDJwCX8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above screenshot shows that the static assets do not have an efficient cache policy. Therefore causing the resource to be downloaded every time and increasing latency.&lt;/p&gt;

&lt;p&gt;Additionally, depending on your website, you might see different results and diagnostic issues you can fix to improve your website performance.&lt;/p&gt;

&lt;p&gt;Also, Google PageSpeed ‘s a free tool to use quickly when running website checks; it does not allow you to simulate network latencies or select different devices to test with. That’s why using a &lt;a href="https://www.lambdatest.com/responsive-test-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;mobile responsive test tool&lt;/a&gt; like LT Browser 2.0 will enable you to set all these parameters and is a good choice for understanding your user’s real experience based on different configurations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This questionnaire of &lt;a href="https://www.lambdatest.com/learning-hub/jasmine-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Jasmine Interview questions&lt;/a&gt; will aid you in giving good insight about Jasmine and how to crack the interview.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Using LT Browser 2.0
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://lambdatest.com/lt-browser?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LT Browser&lt;/a&gt; 2.0 is the next-gen browser to build, test, and debug mobile websites. It allows you to test your website on different mobile device viewports. Additionally, you can create and test your websites on your custom device resolution and viewport and save it for future use. LT Browser 2.0 supports all kinds of platforms and devices ranging from desktops, mobile, tablets, iPhones, etc.&lt;/p&gt;

&lt;p&gt;In addition, LT Browser 2.0 allows you to test your websites against different configurations, such as setting network throttling and performing a full lighthouse check on your website based on these configurations.&lt;/p&gt;

&lt;p&gt;The first step is to download and install LT Browser on your machine. You can follow the documentation to &lt;a href="https://www.lambdatest.com/support/docs/lt-browser-2/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=support_doc" rel="noopener noreferrer"&gt;get started with LT Browser.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After downloading and installing, open the LT Browser and enter the URL of your website, select your favorite screen size, and start debugging.&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%2ABzp0hryHRPipghGN.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%2ABzp0hryHRPipghGN.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have selected Desktop and typed in LambdaTest website for my case. Next, we will generate Lighthouse reports.&lt;/p&gt;

&lt;p&gt;Click on the &lt;strong&gt;Performance Report&lt;/strong&gt; tab to see the performance of your website based on the device size, network throttling, etc., you have selected.&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%2F2640%2F0%2ALStdyybRyhsLS-aj.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%2F2640%2F0%2ALStdyybRyhsLS-aj.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After a few minutes, the results came in. From the screenshot below, you can see a performance reduction based on my browser configuration, network throttling settings, and Internet provider.&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%2F2620%2F0%2AdgrpA-E0uX92t8dX.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%2F2620%2F0%2AdgrpA-E0uX92t8dX.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, you can also see the metrics that need improvements and where the website is lacking speed.&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%2F2572%2F0%2AaC-Bp1374-T47-YO.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%2F2572%2F0%2AaC-Bp1374-T47-YO.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there are any issues, the report will show them and list the opportunities to improve the website’s performance. Your development team can go through the list and fix most of the bugs listed below for better performance on a slow network.&lt;/p&gt;

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

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=video" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay up to date with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this tutorial on how to reduce page load time in JavaScript, we explored how reducing page load time in JavaScript can be achieved by minifying code, using caching, optimizing images, and reducing the number of HTTP requests.&lt;/p&gt;

&lt;p&gt;Additionally, using a content delivery network (CDN) improves page load times by reducing latency and improving performance. By following these steps, developers can ensure that their web pages load quickly and efficiently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Prepare to ace your &lt;a href="https://www.lambdatest.com/learning-hub/nunit-interview-questions?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul_10&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;NUnit interviews questions &lt;/a&gt;with our thorough set of solutions that will enable you to prove your command of the NUnit testing framework.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How do I reduce page loading time?
&lt;/h3&gt;

&lt;p&gt;Providing a better user experience and improving website performance depends on reducing page load time. To decrease page loading time, you can follow the below strategies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Optimize and compress images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minify CSS and JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable browser caching&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use Content Delivery Networks (CDNs)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce HTTP requests&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How can I make JavaScript load faster?
&lt;/h3&gt;

&lt;p&gt;To make JavaScript load faster, you can implement several techniques, including minifying and compressing JavaScript, using asynchronous loading, combining JavaScript files, using caching, and others.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to use Date Picker in Selenium using JavaScript</title>
      <dc:creator>Solomon Eseme</dc:creator>
      <pubDate>Wed, 17 May 2023 12:50:42 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-use-date-picker-in-selenium-using-javascript-4mbl</link>
      <guid>https://forem.com/testmuai/how-to-use-date-picker-in-selenium-using-javascript-4mbl</guid>
      <description>&lt;p&gt;Selenium is widely recognized as one of the top-performing &lt;a href="https://www.lambdatest.com/learning-hub/web-automation-tools?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;web automation tools&lt;/a&gt;. However, its potential extends beyond testing, with numerous use cases leveraging its capabilities. One such application involves automating the process of completing a form within a browser.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-javascript?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium JavaScript tutorial&lt;/a&gt;, we will cover how to use Date Picker in Selenium using JavaScript when filling out a form. We will discuss the best pattern and approach to achieve the solution and explore how we solved this problem in our application.&lt;/p&gt;

&lt;p&gt;So, let’s get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this tutorial, learn what is Regression testing, its importance, types, and how to perform it: &lt;a href="https://www.lambdatest.com/learning-hub/regression-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;https://www.lambdatest.com/learning-hub/regression-testing&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is a popular open-source test automation framework used for &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;. This framework helps you &lt;a href="https://www.lambdatest.com/blog/how-to-write-test-scripts-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;write Selenium test scripts&lt;/a&gt; that can be used to automate the testing of websites and web applications, then execute them in different browsers on multiple platforms using any programming language of your choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Date Picker in Selenium
&lt;/h2&gt;

&lt;p&gt;If your website requires users to fill out their date of birth or any date-related fields and your web page is using any of these date picker components available.&lt;/p&gt;

&lt;p&gt;You might want to test out the approach it will take your users to fill out the form or possibly &lt;a href="https://www.lambdatest.com/blog/how-to-automate-filling-in-web-forms-with-python-using-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automate the process of filling web &lt;/a&gt;forms that require a Date Picker in any website using Selenium with JavaScript.&lt;/p&gt;

&lt;p&gt;How do you achieve this using the Selenium automation tool? I had this problem testing out my web page, and I will share with you how to &lt;a href="https://www.lambdatest.com/blog/automation-testing-with-selenium-javascript/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automate testing with Selenium JavaScript.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, let’s build a web page that contains a Date Picker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Webpage with Date Picker
&lt;/h2&gt;

&lt;p&gt;To learn how to automate Date Picker in Selenium using JavaScript, we’ll use jQuery’s Date Picker demo URL as the test URL to demonstrate the same.&lt;/p&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/selenium-javascript-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium JavaScript testing&lt;/a&gt; tutorial, I’ll be using JavaScript to automate the Date Picker using &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is a sample of the form we have created for this demo:&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%2AX5Dw7FS7ltjoWz9-.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%2F0%2AX5Dw7FS7ltjoWz9-.png" width="643" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we are going to set up Selenium and automate the process of filling out this form. The process is seamless and very simple to get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Selenium with JavaScript
&lt;/h2&gt;

&lt;p&gt;Installing Selenium in your JavaScript project requires some installations on your local machine. Here are some prerequisites you need to have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download and install NodeJS from official NodeJS documentation. You should have NodeJS v6 or newer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you are using the latest version of JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install npm from th*e official &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm website&lt;/a&gt;.*&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download Selenium JavaScript bindings from the official website. The latest versions of Selenium Client and WebDriver are ideal for running your &lt;a href="https://www.lambdatest.com/selenium-javascript-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;JavaScript automation testing&lt;/a&gt; script.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Set up Selenium with Express
&lt;/h2&gt;

&lt;p&gt;If you have successfully installed and set up the following prerequisites, you’re ready to move to the next step. Next, create a project folder for your Selenium Date Picker project. We will call it “&lt;em&gt;selenium-date-picker&lt;/em&gt;”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Install the required dependencies.&lt;/p&gt;

&lt;p&gt;Below are the required dependencies to install:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express selenium-webdriver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AypOc2EOACcwtZlSU.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%2F0%2AypOc2EOACcwtZlSU.png" width="706" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**Step 2: **Create an “index.js” file that will add the configuration for Selenium for using the Date Picker in Selenium using JavaScript.&lt;/p&gt;

&lt;p&gt;Here’s the code snippet for setting up Selenium in the Express framework:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const { By, Builder, Select } = require("selenium-webdriver");
const app = express();
const port = 3002;
let driver;
const URL = "https://jqueryui.com/datepicker/#date-range";
const expected_fr_date = "20";
const expected_to_date = "26";
app.get("/", async (request, response) =&amp;gt; {
 try {
   const data = await DatePickerWithLambdaTest();
   response.status(200).json(data);
 } catch (error) {
   console.log(error);
   response.status(500).json({
     message: "Server error occurred",
   });
 }
});
app.listen(port, () =&amp;gt; {
 console.log(`Example app listening at http://localhost:${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above code snippet shows a simple web server created with Express.js to request from a Date Picker in Selenium using JavaScript.&lt;/p&gt;

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

&lt;p&gt;Let’s walk through the code together and understand the nitty-gritty of it.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Step 1: **Add the required packages and set up the Express server.&lt;br&gt;
First, we need the *express *and *selenium-webdriver&lt;/em&gt; packages. Next, we create an Express server and initialize variables which will be used 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%2F2560%2F0%2AFyD3Nro-uGOt0Isq.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%2F2560%2F0%2AFyD3Nro-uGOt0Isq.png" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create Express Route.&lt;/p&gt;

&lt;p&gt;Next, we create an endpoint to fill out the Date Picker in Selenium using JavaScript and display the result as JSON data. This endpoint will call the &lt;em&gt;DatePickerWithLambdaTest()&lt;/em&gt; function to fill out the date picker and return the data.&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%2F2072%2F0%2AaqddNpW6ByCfXHQZ.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%2F2072%2F0%2AaqddNpW6ByCfXHQZ.png" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test native, hybrid, and web apps on any mobile OS with our free &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Android emulator&lt;/a&gt; online. Sign up to optimize app performance.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use Date Picker in Selenium using JavaScript?
&lt;/h2&gt;

&lt;p&gt;After setting up the Express server, we will create the two functions to fill out the Date Picker and return the data.&lt;/p&gt;

&lt;p&gt;Here’s the code snippet:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function DatePickerWithLocal() {
 try {
   const driver = await new Builder().forBrowser("chrome").build();
   return selectDatePicker(driver);
 } catch (error) {
   throw error;
 } finally {
   await driver.quit();
 }
}
async function DatePickerWithLambdaTest() {
 const USERNAME = ""; //replace with your username
 const KEY = ""; //replace with your accesskey
 const GRID_HOST = "hub.lambdatest.com/wd/hub";
 const capabilities = {
   browserName: "Chrome",
   browserVersion: "107.0",
   "LT:Options": {
     username: USERNAME,
     accessKey: KEY,
     geoLocation: "US",
     platformName: "Windows 10",
     build: "Date Picker",
     project: "Date Picker Example",
     w3c: true,
     plugin: "node_js-node_js",
   },
 };


 const gridUrl = "https://" + USERNAME + ":" + KEY + "@" + GRID_HOST;
 try {
   driver = await new Builder()
     .usingServer(gridUrl)
     .withCapabilities(capabilities)
     .build();


   return await selectDatePicker(driver);
 } catch (error) {
   throw error;
 } finally {
   await driver.quit();
 }
}


async function selectDatePicker(driver) {
 try {
   if (!driver) return;
   await driver.get(URL);
   /**
    * Switching Frames with iframe
    */
   const frame = await driver.findElement(
     By.xpath("//*[@id='content']/iframe")
   );
   await driver.switchTo().frame(frame);


   /**
    * ################################# Steps for the From Date ####################
    */
   const from_date = await driver.findElement(By.xpath('//*[@id="from"]'));
   await from_date.click();


   const from_month = await driver.findElement(
     By.className("ui-datepicker-month")
   );
   const selected_from_month = new Select(from_month);
   await selected_from_month.selectByVisibleText("Jan");
   const from_day = await driver.findElement(
     By.xpath(
       "//td[not(contains(@class,'ui-datepicker-month'))]/a[text()='" +
         expected_fr_date +
         "']"
     )
   );
   await from_day.click();


   /**
    * ################################# Steps for the To Date #####################
    * The same steps like the ones in From Month are repeated except that now the operations are performed on a different web element.
    *   
    */
   const to_date = await driver.findElement(By.xpath("//input[@id='to']"));
   await to_date.click();


   const to_month = await driver.findElement(
     By.xpath("//div/select[@class='ui-datepicker-month']")
   );
   const selected_to_month = new Select(to_month);
   await selected_to_month.selectByVisibleText("Feb");
   const to_day = await driver.findElement(
     By.xpath(
       "//td[not(contains(@class,'ui-datepicker-month'))]/a[text()='" +
         expected_to_date +
         "']"
     )
   );
   await to_day.click();


   /**
    * Get Date values
    */
   const selected_from_date_str = await from_date.getAttribute("value");
   const selected_to_date_str = await to_date.getAttribute("value");
   return {
     from: selected_from_date_str,
     to: selected_to_date_str,
   };
 } catch (error) {
   throw error;
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The code snippet above is the complete section of the index.js that contains the Express server and the routing configuration.&lt;/p&gt;

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

&lt;p&gt;Let’s walk through the code together and understand the nitty-gritty of using Date Picker in Selenium using JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Selenium with local setup.&lt;/p&gt;

&lt;p&gt;The code snippet in the &lt;em&gt;DatePickerWithLocal&lt;/em&gt; shows how to use locally installed Selenium to perform the Date Picker operation. This method runs on your local machine and requires installing the Selenium driver and setting up the correct browser configuration.&lt;br&gt;
We configured and selected a specific browser we wanted to perform the task with and passed the new driver instance to the ‘&lt;em&gt;selectDatePicker&lt;/em&gt;‘ function to operate.&lt;/p&gt;

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

&lt;p&gt;You can learn more about configuring and installing Selenium and its browser driver locally by &lt;a href="https://www.lambdatest.com/blog/web-scraping-with-javascript-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;performing web scraping with Selenium JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Selenium with LambdaTest Grid&lt;/p&gt;

&lt;p&gt;The code snippet in the &lt;em&gt;DatePickerWithLamdaTest&lt;/em&gt; shows how to use LamdaTest Grid to perform the Date Picker operation with Selenium on the cloud.&lt;/p&gt;

&lt;p&gt;JavaScript automation on a cloud-based testing digital experience testing platform like LambdaTest helps you achieve improved browser coverage while performing &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; on over 3000+ browsers and OS combinations.&lt;/p&gt;

&lt;p&gt;By running Selenium JavaScript tests in parallel using LambdaTest cloud-based infrastructure, you can speed up your release cycle significantly, with the potential to increase the overall test execution pace by up to 10 times.&lt;/p&gt;

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

&lt;p&gt;Please subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=video" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel &lt;/a&gt;and stay updated with the latest tutorials on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;No installations are required, only a few configurations, as shown below:&lt;/p&gt;

&lt;p&gt;Before running the operation, please set the following environment variables in your .env file. You can find the username and access key on your &lt;a href="https://accounts.lambdatest.com/detail/profile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Profile&lt;/a&gt; page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash
LT_USERNAME=
LT_ACCESS_KEY=
GRID_HOST=hub.lambdatest.com/wd/hub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, generate your Selenium configuration using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Lambdatest Capabilities Generator&lt;/a&gt;. Set your configuration and copy the JavaScript object to your code, as shown below.&lt;/p&gt;

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

&lt;p&gt;Next, we created a driver using the configuration and capacity before passing the driver to the ‘&lt;em&gt;selectDatePicker&lt;/em&gt;‘ function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Performing the Operation.&lt;/p&gt;

&lt;p&gt;Lastly, we call the &lt;em&gt;selectDatePicker&lt;/em&gt; function to operate. Below is a breakdown of the function.&lt;/p&gt;

&lt;p&gt;First, we check the driver instance to make sure it’s created. Next, we open the webpage where the date picker is located using the ‘&lt;em&gt;driver.get(URL)&lt;/em&gt;’ function. Lastly, we find the first iframe on the page and switch to it using the ‘&lt;em&gt;driver.switchTo().frame()’&lt;/em&gt; function.&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%2ApJtLAoIBH2cw3zr6.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%2F0%2ApJtLAoIBH2cw3zr6.png" width="800" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Furthermore, still inside the function, we started the first operation for the From date by interacting with the input element using Selenium functions as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3196%2F0%2AhelFsIPlIseYus0_.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%2F3196%2F0%2AhelFsIPlIseYus0_.png" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;expected_fr_str&lt;/em&gt; comes from the constants we declared above to specify the specific date we want to select from the calendar.&lt;/p&gt;

&lt;p&gt;Next, we repeat the same thing for the &lt;em&gt;to-date&lt;/em&gt; instance as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F0%2AV_UWvr6vpRLmbzLy.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%2AV_UWvr6vpRLmbzLy.png" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The expected_to_str comes from the constants we declared above to specify the specific date we want to select from the calendar.&lt;/p&gt;

&lt;p&gt;Lastly, we retrieve the chosen date from the input field and return it as an object.&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%2F2736%2F0%2AL89We6BR-rBtOTk5.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%2F2736%2F0%2AL89We6BR-rBtOTk5.png" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you configure everything correctly, you should see a JSON response from your server when you run it on your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Date Picker
&lt;/h2&gt;

&lt;p&gt;To run your test for Date Picker in Selenium using JavaScript, type the following command into your root terminal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Open your browser and locate the web address. After successfully performing running the Date Picker, you should be greeted with a JSON response from your server, like the screenshot below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AabSvhudAJJWjQKex.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%2F0%2AabSvhudAJJWjQKex.png" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far, we have successfully used a Date Picker with Selenium using JavaScript. You can clone the entire code repository from this GitHub Repository.&lt;/p&gt;

&lt;p&gt;If you are a developer or a tester, this &lt;a href="https://www.lambdatest.com/certifications/selenium-javascript-101?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=certification" rel="noopener noreferrer"&gt;Selenium JavaScript 101&lt;/a&gt; certification can help equip you with advanced skills and extensive knowledge in automation testing, enabling you to excel in any JavaScript automation role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=may_17&amp;amp;utm_term=bh&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt; on the most powerful cloud infrastructure. Leverage LambdaTest automation testing for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Selenium is one of the most popular browser automation tools. Therefore achieving simple tasks such as automating the process of filling out a Date Picker can be daunting.&lt;/p&gt;

&lt;p&gt;This article covers in detail how to use Date Picker in Selenium using JavaScript when filling out a form. We discussed the best pattern and approach to achieve the solution and finally explored how we solved this problem in our application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. How to automate Date Picker in JavaScript?
&lt;/h3&gt;

&lt;p&gt;Automating a date picker in JavaScript can be achieved using the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Locate the date picker element on the web page using the DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the .click() method to trigger the date picker to open.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use JavaScript to set the desired date in the date picker element. Depending on the date picker plugin used, you can directly set the date value using the value attribute or similar property. Alternatively, you may need to simulate user actions such as clicking the previous/next month buttons, selecting a date from a calendar, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. How to set Date Picker in Selenium?
&lt;/h3&gt;

&lt;p&gt;To set a date picker in Selenium, you can follow the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Locate the date picker element on the web page using any of the Selenium locators like id, name, class, xpath, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the .click() method to open the date picker widget.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Depending on the date picker widget used, you can either directly set the date value using the sendKeys() method, or you may need to simulate user actions like clicking on the previous/next month buttons, selecting a date from a calendar, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>selenium</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>testing</category>
    </item>
    <item>
      <title>How To Perform Web Scraping With JavaScript And Selenium</title>
      <dc:creator>Solomon Eseme</dc:creator>
      <pubDate>Thu, 24 Nov 2022 12:50:51 +0000</pubDate>
      <link>https://forem.com/testmuai/how-to-perform-web-scraping-with-javascript-and-selenium-1d0k</link>
      <guid>https://forem.com/testmuai/how-to-perform-web-scraping-with-javascript-and-selenium-1d0k</guid>
      <description>&lt;p&gt;Web scraping with JavaScript is a very useful technique to extract data from the Internet for presentation or analysis. However, in this era of dynamic websites, it becomes difficult to accurately extract data from the web because of the ever-changing nature of data.&lt;/p&gt;

&lt;p&gt;In the past, we used libraries such as &lt;em&gt;urllib&lt;/em&gt; or &lt;em&gt;requests&lt;/em&gt; to read data from webpages, but things started falling apart with dynamic websites. For websites that are not static, using a common ajax call or requests will simply not work.&lt;/p&gt;

&lt;p&gt;Selenium framework was introduced for such automation to help in the aspect of dynamic data and other important features.&lt;/p&gt;

&lt;p&gt;When we were developing an automated job portal for backend engineers, we needed a reliable web scraping framework to help us scrape over 20 job portals and return over a thousand jobs each, and Selenium was the answer.&lt;/p&gt;

&lt;p&gt;But before we delve into &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;what is Selenium&lt;/a&gt; and perform web scraping with JavaScript and Selenium, let’s explore what web scraping is all about?&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Web Scraping?
&lt;/h2&gt;

&lt;p&gt;Web scraping is the process of extracting data from the Internet for storage in different formats or for further processing and analysis. It can also be referred to as web harvesting or web data extraction.&lt;/p&gt;

&lt;p&gt;By Web scraping with JavaScript and Selenium, we basically automates the manual process of extracting data from the Internet and storing it for further processing.&lt;/p&gt;

&lt;p&gt;It can be useful to extract data for different purposes such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Academic or business Research&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Historical Data Analysis&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Price comparisons&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SEO&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Brand protection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ad verification&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;and many other use cases&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use web scraping to generate product reviews from review websites to help you decide to buy a particular product.&lt;/p&gt;

&lt;p&gt;You can also use web scraping to scrape thousands of job portals for specific jobs you’re interested in applying for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Web Scraping with JavaScript
&lt;/h2&gt;

&lt;p&gt;Below are a few benefits of web scraping:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Extracting product details of e-commerce websites such as prices, product names, images, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web scraping is very useful in research as it can help to gather structured data from multiple websites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gathering data from different sources for analysis can be automated with web scraping easily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be used to collect data for testing and training machine learning models.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benefit of web scraping is endless and introduces different thoughtful insights and possibilities to businesses.&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%2AWPCoCutncQ00nXK1.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%2F0%2AWPCoCutncQ00nXK1.png" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to check for data protection?
&lt;/h2&gt;

&lt;p&gt;In general, web scraping is not illegal, but there are some caveats to it, and to some extent, it has become illegal.&lt;/p&gt;

&lt;p&gt;It’s always very important to be careful and check out some of the different terms you should consider when web scraping to determine if your actions are illegal or not.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copyright Infringement&lt;/strong&gt;&lt;br&gt;
Every website should have a document stating whether the website’s content can be web scraped or not. You can check the copyright document to gain more insights into the possibilities provided by the company on web scraping.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Robot.txt&lt;/strong&gt;&lt;br&gt;
The robot.txt file also provides strict information on web scraping, and you should adhere to this file’s information or legal stand. If it says no web scraping, then it should be respected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using API&lt;/strong&gt;&lt;br&gt;
If a business provides a public API that users can access the data in the business, then you should adhere to using the API instead of web scraping it to avoid legal action.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terms of Services&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Terms of service is a good place to find all the information on how the website’s content should be used and accessed. It states the possibilities of web scraping the stand the website is taking on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scraping Public Content&lt;/strong&gt;&lt;br&gt;
Web scraping of public content is not a crime, but if the content owner forbids it — web scraping companies should comply.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we understand our stand on the legality of web scraping, what methods are there to web scrape data either for a small use case or web scraping at scale? Next, let’s explore the different methods and tools available for web scraping.&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%2Ap17Q90bMawBTw_Ze.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%2F0%2Ap17Q90bMawBTw_Ze.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Complete &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;WebDriver&lt;/a&gt; Tutorial- A Guide on Selenium WebDriver Automation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Scraping Tools
&lt;/h2&gt;

&lt;p&gt;This is the most popular web scraping method where a business deploys an already made software for all their web scraping use cases.&lt;/p&gt;

&lt;p&gt;If you want to access and gather data at scale, you need good web scraping tools that can surpass IP blocking, cloaking, and ReCaptcha. There are popular tools such as Scrapy, Beautiful Soup, Scrapebox, Scrapy Proxy Middleware, Octoparse, Parsehub, and Apify.&lt;/p&gt;

&lt;p&gt;These tools help you with your web scraping task at scale and can surpass different obstacles to help you achieve your goals.&lt;/p&gt;

&lt;p&gt;Selenium is a popular open-source web automation framework used for &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;. This framework helps you write &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; test scripts that can be used to &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automate testing&lt;/a&gt; of websites and web applications, then execute them in different browsers on multiple platforms using any programming language of your choice. However, it can be adapted to solve dynamic web scraping problems, as we will demonstrate in the blog on how you can do web scraping using JavaScript and Selenium.&lt;/p&gt;

&lt;p&gt;Selenium has three major components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/run-selenium-ide-test-on-online-selenium-grid/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt;: It is a browser plugin — a faster, easier way to create, execute, and debug your Selenium scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&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=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt;: It is a set of portable APIs that help you write automated tests in any language that runs on top of your browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&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=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Grid:&lt;/a&gt; It automates the process of distributing and scaling tests across multiple browsers, operating systems, and platforms.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When writing this blog on web scraping with JavaScript and Selenium, the latest version of Selenium is &lt;a href="https://www.lambdatest.com/learning-hub/selenium-4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium 4&lt;/a&gt;. If you are intrigued to know more about &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=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;what is new in Selenium 4&lt;/a&gt;, you can go through this video:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Testing&lt;/a&gt; Automation Cloud — Test on Selenium Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of using Selenium with JavaScript for Web Scraping
&lt;/h2&gt;

&lt;p&gt;The benefits of using Selenium are limitless and can be used in different aspects of web scraping with JavaScript — from scraping static to dynamic websites. Below are a few &lt;a href="https://www.lambdatest.com/blog/13-reasons-why-selenium-webdriver-should-be-your-first-choice-for-automation-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;benefits of using Selenium WebDriver&lt;/a&gt; for your next web scraping project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Selenium WebDriver can be configured to scrape a website on browsers whose browser drivers are available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Selenium WebDriver to scrape complicated websites with dynamic contents since some needed data requires HTTP requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform &lt;a href="https://www.lambdatest.com/automated-screenshot?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated screenshot&lt;/a&gt; testing by taking numerous screenshots of the web pages as you scrape the web pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With the Selenium WebDriver, you can simulate a real user working with a browser by loading all resources and downloading browser cookies.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this &lt;a href="https://www.lambdatest.com/learning-hub/selenium-javascript?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;Selenium JavaScript tutorial&lt;/a&gt;, we will learn how to perform web scraping with JavaScript and Selenium on our local machine and also on LambdaTest &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will be web scraping the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube channel&lt;/a&gt;, displaying the list of videos on a webpage using Selenium, and converting the information to JSON data.&lt;/p&gt;

&lt;p&gt;If you are new to this channel, please subscribe to the LambdaTest YouTube Channel and stay updated with the latest tutorials on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;Accelerate JavaScript Automation with Parallel testing. &lt;a href="https://accounts.lambdatest.com/register?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=register" rel="noopener noreferrer"&gt;Try LambdaTest Now!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Web Scraping with JavaScript and Selenium
&lt;/h2&gt;

&lt;p&gt;One of the benefits of Selenium is that it can web-scrape dynamic JavaScript pages where there are dynamic interactions such as hovering over menu items. In this section of this blog on web scraping with JavaScript and Selenium, we will demonstrate how to web scrape YouTube videos and display the data as JSON using Selenium and JavaScript.&lt;/p&gt;

&lt;p&gt;Selenium encapsulates the complexity of building an automation tool for dynamic pages and makes it easy by simplifying installing and configuring the package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Testing tool&lt;/a&gt; Automation Cloud — Test on Selenium Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before you continue below, you should be familiar with Node.js and Express.js — a Node.js framework. If you are new to &lt;a href="https://www.lambdatest.com/testing-cloud/express-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Express testing&lt;/a&gt;, you can learn more about it through this guide on &lt;a href="https://www.lambdatest.com/blog/express-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;getting started quickly with Express testing&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;We will continue by installing the necessary packages and software to implement web scraping with JavaScript and Selenium.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Visual Studio Code:&lt;/strong&gt; This is the code editor we will use in this demo, though you can go with any code editor of your choice. You could use any other IDE of your choice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Browser Driver:&lt;/strong&gt; To run the Selenium testing drivers on your machine, you need to download the drivers from the following locations according to the browser of your choice.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;BROWSER&lt;/td&gt;
        &lt;td&gt;DOWNLOAD LOCATION&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Opera&lt;/td&gt;
        &lt;td&gt;https://github.com/operasoftware/operachromiumdriver/releases&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Firefox&lt;/td&gt;
        &lt;td&gt;https://github.com/mozilla/geckodriver/releases&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Chrome&lt;/td&gt;
        &lt;td&gt;http://chromedriver.chromium.org/downloads&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Internet Explorer&lt;/td&gt;
        &lt;td&gt;https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;Microsoft Edge&lt;/td&gt;
        &lt;td&gt;https://blogs.windows.com/msedgedev/2015/07/23/bringing-automated-testing-to-microsoft-edge-through-webdriver/&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;After downloading any of the drivers, make sure to install it and set it up properly according to your operating system.&lt;/p&gt;

&lt;p&gt;After successfully installing and configuring the browser driver, we will explore how to create a new project and start scraping YouTube videos in the next section of this blog on web scraping with JavaScript and Selenium.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Project
&lt;/h2&gt;

&lt;p&gt;After the installation, we will create a new VSCode Node.js project and add the following libraries to our package.json file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ensure you have Node.js installed and configured properly in your operating system. You can download and install it from the Node.js official website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Let’s install the following packages:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```bash
npm install express selenium-webdriver
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2296%2F0%2A_5h5JWh4W71yhk7b.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%2F2296%2F0%2A_5h5JWh4W71yhk7b.png" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- After installing the libraries, let’s create an &lt;em&gt;**index.js *&lt;/em&gt;*file inside the root directory and set up our express server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ```bash
    touch index.js
    ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the express server to listen to incoming requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ```js
    const express = require('express')
    const { Builder, By } = require('selenium-webdriver');

    const app = express()
    const port = 3000
    app.get('/', (request, response) =&amp;gt; {
     // Web Scraping Code here
    })
    app.listen(port, () =&amp;gt; {
      console.log(`Example app listening at http://localhost:${port}`)
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;4- The code snippet above creates a new Express server and listens to incoming requests from the user. In the next section of this blog on web scraping with JavaScript and Selenium, we will use the &lt;strong&gt;&lt;em&gt;selenium-webdriver&lt;/em&gt;&lt;/strong&gt; library we installed to web scrape our YouTube videos.&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube Web Scraping with JavaScript and Selenium
&lt;/h2&gt;

&lt;p&gt;In this demonstration, we scrape the following data from the LambdaTest YouTube channel and display it as JSON:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Video Title&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Video Views&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Video Published Date&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2AhU7o6JS9tA-KczGM.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%2F2048%2F0%2AhU7o6JS9tA-KczGM.png" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can implement it using the cloud-based Selenium automation grid provided by LambdaTest, which will take away all the manual configuration both in development and in production.&lt;/p&gt;

&lt;p&gt;LambdaTest is a &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that allows you to automate browsers with Selenium, Appium, and other frameworks. With LambdaTest’s Selenium Grid, you can run Selenium tests in parallel over an &lt;a href="https://www.lambdatest.com/online-browser-farm?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;online browser farm &lt;/a&gt;of 3000+ browsers and platform configurations.&lt;/p&gt;

&lt;p&gt;Below is a simple walkthrough of how the scraping is going to happen before delving into the implementation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the YouTube channel videos page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It scrolls until the end of the page to scrape all the videos available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retrieves the video title, views, and upload details using a loop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the scraped information to JSON.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const { Builder, By } = require('selenium-webdriver');

const app = express();
const port = 3000;
app.get('/', async (request, response) =&amp;gt; {
 // Web Scraping Code here
 try {
   const data = await WebScrapingLocalTest();
   response.status(200).json(data);
 } catch (error) {
   response.status(500).json({
     message: 'Server error occurred',
   });
 }
});
app.listen(port, () =&amp;gt; {
 console.log(`Example app listening at http://localhost:${port}`);
});

async function WebScrapingLocalTest() {
 try {
   driver = await new Builder().forBrowser('chrome').build();
   await driver.get('https://www.youtube.com/c/LambdaTest/videos');
   const allVideos = await driver.findElements(
     By.css('ytd-grid-video-renderer.style-scope.ytd-grid-renderer')
   );
   return await getVideos(allVideos);
 } catch (error) {
   throw new Error(error);
 } finally {
   await driver.quit();
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;p&gt;Let’s walk through the code together and understand the nitty-gritty of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Add required packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we require the express and selenium-webdriver packages, and next we created an Express server to handle the incoming request. The request is handled by calling the WebScrapingTest function.&lt;/p&gt;

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



```js

    app.get('/', async (request, response) =&amp;gt; {
     // Web Scraping Code here
     try {
       const data = await WebScrapingLocalTest();
       response.status(200).json(data);
     } catch (error) {
       response.status(500).json({
         message: 'Server error occurred',
       });
     }
    });

    async function getVideos(videos) {
     let videoDetails = [];
     try {
       for (const video of videos) {
         const title = await video.findElement(By.id('video-title')).getText();
         const views = await video
           .findElement(By.xpath(".//*[@id='metadata-line']/span[1]"))
           .getText();
         const date = await video
           .findElement(By.xpath(".//*[@id='metadata-line']/span[2]"))
           .getText();
         videoDetails.push({
           title: title ?? '',
           views: views ?? '',
           publishedDate: date ?? '',
         });
       }
     } catch (error) {
       console.log(error);
     }
     return videoDetails;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create an instance of Selenium WebDriver&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inside the openChromeTest function, we created an instance of the Builder class from the Selenium Webdriver package we imported earlier. We also pipe the forBrowser method used to indicate the browser to use for the web scraping and lastly, we call the build method, which creates a new WebDriver client based on this builder’s current configuration.&lt;/p&gt;

&lt;p&gt;With the instance of the builder, we passed in the official LambdaTest YouTube videos URL in the get method of the builder class.&lt;br&gt;
&lt;/p&gt;

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

    driver = await new Builder().forBrowser('chrome').build();
       await driver.get('https://www.youtube.com/c/LambdaTest/videos');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Load all the YouTube Videos on the page&lt;/strong&gt;&lt;br&gt;
Next, we will load all the videos within the page and collect specific information using a loop in JavaScript.&lt;/p&gt;

&lt;p&gt;To do that, we need to target a specific element in the YouTube Videos page that contains all the videos using the Chrome inspector tool, we can select any element within the webpage. Below is a screenshot showing the element and the &lt;a href="https://www.lambdatest.com/blog/how-pro-testers-use-css-selectors-in-selenium-automation-scripts/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS selector&lt;/a&gt; to use.&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%2F2698%2F0%2A_680kYgHLr8cnaFn.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%2F2698%2F0%2A_680kYgHLr8cnaFn.png" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As of the time of writing, the class attribute to target is &lt;em&gt;ytd-grid-video-renderer style-scope ytd-grid-renderer&lt;/em&gt;, which is a combination of the CSS class property of the parent container and the individual video container.&lt;/p&gt;

&lt;p&gt;Next, we are going to convert the classes to CSS QuerySelector and target all the videos using the &lt;a href="https://www.lambdatest.com/blog/findelement-and-findelements-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;FindElements method in the Selenium WebDriver&lt;/a&gt; and &lt;strong&gt;By&lt;/strong&gt; instance class.&lt;br&gt;
Here is how it looks:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const allVideos = await driver.findElements(
         By.css('ytd-grid-video-renderer.style-scope.ytd-grid-renderer')
       );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Selenium uses the By instance class to represent different query selectors, so you can select elements using &lt;a href="https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium locators&lt;/a&gt; like CSS name, ID, Class, etc.&lt;/p&gt;

&lt;p&gt;Finally, the findElements method returns an object of all the selected HTML DOM Nodes called WebElement, which we will loop through to retrieve metadata of the videos while performing web scraping with JavaScript and Selenium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Converting to JSON&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lastly, we loop through the WebElement and retrieve metadata of the videos such as the video title, video views, and video published date.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; async function getVideos(videos) {
 let videoDetails = [];
 try {
   for (const video of videos) {
     const title = await video.findElement(By.id('video-title')).getText();
     const views = await video
       .findElement(By.xpath(".//*[@id='metadata-line']/span[1]"))
       .getText();
     const date = await video
       .findElement(By.xpath(".//*[@id='metadata-line']/span[2]"))
       .getText();
     videoDetails.push({
       title: title ?? '',
       views: views ?? '',
       publishedDate: date ?? '',
     });
   }
 } catch (error) {
   console.log(error);
 }
 return videoDetails;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In the code above, we are using both the &lt;a href="https://www.lambdatest.com/blog/complete-guide-for-using-xpath-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;XPath selectors&lt;/a&gt; to accomplish our task of retrieving basic video information. This screenshot below shows you how to retrieve the XPath of a particular element in a webpage.&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%2F2702%2F0%2Am8-curbVygtcZvZw.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%2F2702%2F0%2Am8-curbVygtcZvZw.png" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Secondly, We are also using the &lt;a href="https://www.lambdatest.com/blog/making-the-move-with-id-locator-in-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;ID selector&lt;/a&gt; to retrieve the video title. This screenshot shows where to get the ID for the video title element on YouTube using the Inspector tool:&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%2F2698%2F0%2Ajhkd-Hd1cJ4K0N1B.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%2F2698%2F0%2Ajhkd-Hd1cJ4K0N1B.png" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Complete &lt;a href="https://www.lambdatest.com/learning-hub/webdriver?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;WebDriver&lt;/a&gt; Tutorial- A Guide on Selenium WebDriver Automation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Display the JSON data
&lt;/h2&gt;

&lt;p&gt;After successfully performing YouTube web scraping with JavaScript and Selenium, we convert them into JSON and send them as a response to our request using the Express server. Finally, we are ready to test the new web scrapper.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start a new development server using the following command:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
bash
    node index.js


    ```
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2- Open the Chrome browser and visit localhost:3002, assuming you use the same port number from the demo.&lt;/p&gt;

&lt;p&gt;3- You should be greeted with JSON data of the YouTube videos after a few seconds, like the screenshot 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%2F2202%2F0%2AxzUy2JYngJaYMqph.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%2F2202%2F0%2AxzUy2JYngJaYMqph.png" alt="A screenshot showing the result of web scraping with JavaScript and Selenium on the LambdaTest YouTube videos page." width="800" height="833"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you love testing as much as I do, you’re going to enjoy learning more about one of the most powerful tools I know of — Selenium WebDriver with JavaScript. This video tutorial covers everything you need to know.&lt;/p&gt;
&lt;h2&gt;
  
  
  Web Scraping with JavaScript and Selenium on cloud-based Selenium Grid
&lt;/h2&gt;

&lt;p&gt;In the previous section, we performed web scraping with JavaScript and Selenium on our local machine. One of the shortcomings of this approach is that you need to install and configure the Browser drivers locally.&lt;/p&gt;

&lt;p&gt;Assuming you need to use multiple browsers to perform that automation, you must also manually install and configure each browser. This is where a cloud-based grid can be super impactful, as you can perform &lt;a href="https://www.lambdatest.com/javascript-automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;JavaScript automation testing&lt;/a&gt; in parallel on various browser and platform combinations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/benefits-of-cloud-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cloud testing&lt;/a&gt; platforms like LambdaTest allow you to perform &lt;a href="https://www.lambdatest.com/live-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;live testing&lt;/a&gt; and run parallel tests on 3000+ real browsers and their different versions. It provides you access to thousands of browsers for mobile and &lt;a href="https://www.lambdatest.com/web-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;web testing&lt;/a&gt; to help you gain the maximum test coverage during the process of Selenium web automation.&lt;br&gt;
Let’s look at how to run the Selenium automation test with JavaScript on LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Let’s start by creating a free account on the LambdaTest platform. Once you log in, fetch your unique username and access key from the LambdaTest Profile Section of the website.&lt;/p&gt;

&lt;p&gt;**Step 2: **Make the following configuration changes to your existing code:&lt;br&gt;
Provide username and access key.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Provide username and access key.&lt;/p&gt;

&lt;p&gt;const USERNAME = 'YOUR_USERNAME'; //replace with your username&lt;br&gt;
    const KEY = 'YOUR_KEY'; //replace with your accesskey&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Provide the host corresponding to the LambdaTest platform.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const GRID_URL = 'hub.lambdatest.com/wd/hub';
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate the desired browser capabilities using &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;LambdaTest Capabilities Generator&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const capabilities = {
         build: 'Web Scraping with JavaScript and Selenium',
         name: 'Youtube Videos',
         platform: 'Windows 10',
         browserName: 'Chrome',
         version: '90.0',
         selenium_version: '3.13.0',
         'chrome.driver': '90.0',
        };


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

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Provide the gridUrl. You can also find this value from the &lt;a href="https://accounts.lambdatest.com/login?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=login" rel="noopener noreferrer"&gt;LambdaTest Dashboard&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_URL;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, edit the code to build and instantiate the browser on the designated platform.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function WebScrapingWithLambdaTest() {
 try {
   driver = await new Builder()
     .usingServer(gridUrl)
     .withCapabilities(capabilities)
     .build();
   await driver.get('https://www.youtube.com/c/LambdaTest/videos');
   const allVideos = await driver.findElements(
     By.css('ytd-grid-video-renderer.style-scope.ytd-grid-renderer')
   );
   return await getVideos(allVideos);
 } catch (error) {
   throw new Error(error);
 } finally {
   await driver.quit();
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the final implementation of Selenium automation with JavaScript that will be run on LambdaTest’s cloud-based Selenium Grid:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

app.get('/lambdatest', async (request, response) =&amp;gt; {
         try {
           const data = await WebScrapingWithLambdaTest();
           response.status(200).json(data);
         } catch (error) {
           response.status(500).json({
             message: 'Server error occurred',
           });
         }
        });
        const USERNAME = 'YOUR_USERNAME'; //replace with your username
        const KEY = 'YOUR_KEY'; //replace with your accesskey
        const GRID_URL = 'hub.lambdatest.com/wd/hub';
        const capabilities = {
         build: 'JavaScript and Selenium Testing',
         name: 'Google search',
         platform: 'Windows 10',
         geoLocation: 'US',
         browserName: 'Chrome',
         version: '90.0',
         selenium_version: '3.13.0',
         'chrome.driver': '90.0',
        };

        const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_URL;

        async function WebScrapingWithLambdaTest() {
         try {
           driver = await new Builder()
             .usingServer(gridUrl)
             .withCapabilities(capabilities)
             .build();
           await driver.get('https://www.youtube.com/c/LambdaTest/videos');

           const allVideos = await driver.findElements(
             By.css('ytd-grid-video-renderer.style-scope.ytd-grid-renderer')
           );
           return await getVideos(allVideos);
         } catch (error) {
           throw new Error(error);
         } finally {
           await driver.quit();
         }
        }


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

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Finally, it’s time to run the test on the LambdaTest grid. Trigger the following command on the terminal to run the &lt;a href="https://www.lambdatest.com/blog/automation-testing-with-selenium-javascript/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing with Selenium JavaScript&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;



 ```js
        node index.js
        ```




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

&lt;/div&gt;


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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Automation&lt;/a&gt; Cloud - Test on Selenium Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Drawbacks of using Selenium for Web Scraping with JavaScript
&lt;/h2&gt;

&lt;p&gt;In this blog, we have seen how to perform web scraping with JavaScript and Selenium. However, there are some drawbacks to using any particular technology (or tool/framework), and Selenium is not exempted. Below are some of the drawbacks of using Selenium for web scraping.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When using Selenium for web scraping, it can automatically download unnecessary files. For instance, if you’re only interested in the text data of a webpage, Selenium will also download the assets (i.e., CSS, HTML, JS, and other files) needed to render the web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It consumes time and resources when using Selenium WebDriver because it downloads unnecessary files to render the web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web Scraping with Selenium is slow since it waits for the entire page to be loaded before you can start accessing data. To learn more about waits, you can read through this blog on &lt;a href="https://www.lambdatest.com/blog/types-of-waits-in-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;types of waits in Selenium&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Watch this video to learn what are waits in Selenium and how to handle them using different methods like hard-coded pauses and by combining explicit waits with different design patterns.&lt;/p&gt;

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

&lt;p&gt;So far, we have detailed a few drawbacks you need to look out for when web scraping with JavaScript and Selenium. Let’s also explore the limitless possibilities and benefits of using Selenium for web scraping.&lt;/p&gt;

&lt;p&gt;If you’re a JavaScript developer serious about &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing&lt;/a&gt;, this certification will give you the hard-core skills and in-depth knowledge needed to excel in any JavaScript automation role.&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%2Aqpn7hp669LNByPOK.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%2F0%2Aqpn7hp669LNByPOK.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

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

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

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Check this out: Online &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Safari Browser For Windows&lt;/a&gt; - Say No To Safari VM! Perform Cross Browser Compatibility Testing On All Safari Browser Versions Across Real Browsers And Operating Systems. &lt;a href="https://www.lambdatest.com/safari-browser-for-windows" rel="noopener noreferrer"&gt;https://www.lambdatest.com/safari-browser-for-windows&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Web scraping is an important technique to extract data. It eliminates the manual process of extracting public data. Web scraping is also very accurate and less time-consuming. It can also be configured to retrieve dynamic websites using Selenium and JavaScript.&lt;/p&gt;

&lt;p&gt;In this blog on web scraping with JavaScript and Selenium, we have explored the benefits of web scraping, which can not be overemphasized, the different web scraping tools, and Selenium which stands as the best tool for automated testing and dynamic web scraping tools.&lt;/p&gt;

&lt;p&gt;We scraped all the content of the official LambdaTest YouTube channel and converted them into JSON, automatically extracting the titles and authors to generate an author matrix, among other useful insights.&lt;/p&gt;

&lt;p&gt;If you are interested in learning more about web scraping using Selenium using other languages like C#, you can go through this article on &lt;a href="https://www.lambdatest.com/blog/scraping-dynamic-web-pages/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=nov24_sd&amp;amp;utm_term=sd&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;scraping dynamic web pages using Selenium and C#.&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%2F2400%2F0%2Aw_gWv9OTBaq-9ajO.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%2F2400%2F0%2Aw_gWv9OTBaq-9ajO.png" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
