Open In App

Navigating links in Selenium JavaScript

Improve
Improve
Like Article
Like
Save
Share
Report

Selenium is an automation tool use for performing automation testing on web browsers. Because of the vast features of selenium it is very famous. Selenium supports multiple programming languages like JavaScript, Python, C# and few others. Now suppose you want to automate a web browser then what will be your very first step? So basically you will first of all try to open that web browser. So in this article, we will talk about how we can automatically open a web browser or simply a url using Selenium JavaScript.  

But before getting to know about how to navigate to a url please make sure that you have gone through Selenium JavaScript Installation article first.

How to navigate links in Python JavaScript: In selenium, if we want to navigate to a url then we can simply use get method. 

 

Syntax:

driver.get(url");

Approach: Our task is to write an automation script in JavaScript that will automatically open geeksforgeeks web page. In order to perform the task of navigating to geeksforgeeks website we have to follow the following steps:

  • Create a webdriver (here chromedriver for chrome browser).
  • Build a new window of chrome using the chromedriver.
  • Navigate to geeksforgeeks website using the get method.

Below is the implementation of the above approach:

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 to run the application: 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:

This wraps our article on Opening a URL in Selenium JavaScript. If you want to explore more about what exactly is this selenium and its introduction then please give Selenium Introduction a read.


Last Updated : 14 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads