How to load a URL in browser without using get() or navigate() method in Selenium

Hello Folks,

In last post, we have seen in details how to open a URL in selenium webdriver.

Do you know that we can open a URL without using any browser as well?  It is frequently asked interview question as well. Let’s learn it.

Let’s perform some steps first:

  1. Open a browser.
  2. Press F12.
  3. Switch to Console tab.
  4. Type ” window.location=’https://www.redbus.in’ “(exclude double quotes) and hit Enter key.
  5. You will notice that redbus website is loaded.

This is the way of loading URL without using any methods like get() or navigate(). Above statement is called as javaScript command. We will see javaScript concepts later. In this post we will just learn how to execute a javaScript command through selenium.

Complete JAVA program:

Notes:

  1. It also holds the execution of next statement till website is loaded completely.
  2. It also throws page load time exception after 300 seconds.
  3. It also keeps current browser session history and you can navigate back and forward.

Java Program:

Output:
Execution Starts
Browser opened.
https://www.flipkart.com/
https://www.facebook.com/
https://www.flipkart.com/
https://www.facebook.com/

I hope you must have learnt new concept.

If you like my posts, please like, comment, share and subscribe. If you have any feedback or suggestions, feel free to contact me.

If you feel like my posts are helping you in learning, help me in running this website by donating some bucks.

Thank you!!

#HappyLearning

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Writing technical posts and creating YouTube videos are my hobbies.

6 thoughts on “How to load a URL in browser without using get() or navigate() method in Selenium

      1. Amod Sir, am not getting any timeout in console. am just getting below mentioned set of lines :

        browser opened
        about:blank
        about:blank
        about:blank
        about:blank
        1500884784173 Marionette INFO New connections will no longer be accepted

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.