Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Selenium JavaScript Installation

  • Difficulty Level : Easy
  • Last Updated : 18 Oct, 2021

Selenium is a tool that helps us automate anything present on the web. Breaking this definition down to even simpler terms than selenium provides us the ability to interact with the web browser automatically using codes. From login to a website to like, share, or comment on a post we can do it all automatically with the help of selenium. So if you are thinking that you will write a code and once you run that code things will automatically get done on the web, then “yes” you are correct, with the help of selenium we can control the actions automatically that we do on the web.

If you want to explore more about the interesting basic concepts of selenium then please give basics of selenium article a read.

In this article, we will see how to install selenium and make the required setup for running web automation using selenium with javascript.

Selenium JavaScript Installation

Step 1. Install Node

First and foremost in order to run selenium with javascript, we must have node installed. To check how to install node in Linux or windows, please give how to install node on linux or how to install node on windows a read.

Step 2. Create package.json File

After having a node in our system now we need to initialize the project by creating a package.json file and for doing this we will open a terminal in the location where we are running the project and then will provide the following command.

npm init

Step 3. Install Selenium Webdriver

Now we have to install selenium-webdriver package and for doing this we simply have to run the following command.

npm install selenium-webdriver

Step 4.  Install Driver For Browser

Finally we have to install a browser-specific webdriver and in this article series of web automation using selenium javascript, we will be automating and using chrome browser that’s why we will install chromedriver with the following command.

npm install chromedriver

If you want to run automation in a different browser then you can install webdriver of that particle browser.

Step 5. Testing simple code:

Following is a simple code that will open geeksforgeeks website using selenium with javascript. 

Javascript




// Require selenium webdriver
let webdriver = require("selenium-webdriver");
  
// Require webdriver for chrome
// browser called chromedriver
require("chromedriver");
  
// Build new window of chrome
let driver =  new webdriver.Builder()
    .forBrowser("chrome").build();
  
// Open geeksforgeeks using get method

Step 6. Running the code:

In order to run the code we can simply use the normal method of running a node file and that is the following

node file_name.js 

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!