DEV Community

Cover image for Selenium- How to Automate web browser
Krishna Kumar
Krishna Kumar

Posted on • Originally published at krishnakumar.hashnode.dev on

Selenium- How to Automate web browser

What is selenium?

Selenium is an open source tool that automates browsers. Selenium webdriver is one of the top web automation testing tool. it provides a single interface that let you write test scripts in programming languages.

Main features of selenium web drivers are:-

  • Open source
  • Cross-platform
  • Automates all major browsers like Chrome, Internet explorer, Microsoft edge, Firefox, Safari, Opera
  • We can write the tests in various languages like Java, Python, Node.js, PHP, Ruby, Perl, C# and many more
  • Runs on JSON webdriver protocols over HTTP

selenium-web-driver-mc-slide1.png

Installing Selenium Weebdriver Package for Node.js

  1. First install Node.js from the official website
  2. Install selenium webdriver for node.js

Writing and running the first script in node.js

write the sample selenium code as shown in the below example and save it with first.js

  const webdriver = require("selenium-webdriver");

    // Declare driver and open web browser
  var driver = new webdriver.Builder().forBrowser('chrome').build();

  // it will open the URL which is passed as an argument
  driver.get('https://www.softpost.org');
  // here driver will stop and close the browser window
  driver.quit();

Enter fullscreen mode Exit fullscreen mode

After that you can run the above node.js code using the below command

      node first.js

Enter fullscreen mode Exit fullscreen mode

Thank you for reading feel free to give feedback! 🙂

Top comments (0)