Attempting to use the getCurrentUrl() function to retrieve the current URL and subsequently opening it in a new tab

I am attempting to retrieve a URL and open it in 3 new tabs, but encountering errors in the process:

browser.getCurrentUrl().then(url => {
        browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('t').perform();
        browser.sleep(2000);
        browser.getAllWindowHandles().then(function (handles) {
        browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows  //  // 
        browser.get(url)
     
      });
    });

Error:

  Failed: null value in entry: name=null

Answer №1

Chrome driver has certain limitations when it comes to simulating browser behavior, such as the inability to use sendKeys to open a new tab in your code. However, there is an alternative method you can use to achieve the same goal, which involves using 'window.open()'. Below is a modified version of your code snippet that may be helpful to you.

     browser.getCurrentUrl().then(url => {
            browser.executeScript('window.open()').then( () => {
            browser.sleep(2000);
            browser.getAllWindowHandles().then(function (handles) {
            browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows  //  // 
            browser.get(url);
          });
      });
   });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason that server.js is always excluded from the Webpack build process?

I am currently utilizing Vue.js 3 for the front end of my application, while employing Node/Express for the back-end. My goal is to implement server side rendering, but I have encountered some challenges along the way. As far as I can tell, the client-sid ...

What is preventing me from using jQuery to dynamically insert HTML onto the page?

Below is the HTML code for a Bootstrap Modal dialog box: <div class="modal fade" id="rebateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> ...

Tips on updating the date format of Vuetify's calendar

I am currently working on implementing inputted events into the Vuetify calendar provided in this link: https://github.com/vuetifyjs/vuetify/blob/master/packages/docs/src/examples/calendars/complex/events.vue. The issue I'm facing is that when I try ...

Warning: Unhandled promise rejection in MSSQL with NodeJS detected

Currently, I am in the process of experimenting with NodeJS to set up an API. However, whenever SQL encounters an error related to NULL columns, my http call gets stuck, and the error is displayed in the node console. The specific error I encounter is: ...

Looking for assistance in correctly identifying types in react-leaflet for TypeScript?

Embarking on my 'first' project involving react-scripts-ts and react-leaflet. I am attempting to create a class that should be fairly straightforward: import {map, TileLayer, Popup, Marker } from 'react-leaflet'; class LeafletMap exte ...

Combining Data Structures in Javascript for Visualization in VueJS

Welcome to my first time asking a question. I am currently working on integrating data from two different API endpoints served by a Django Rest Framework backend and displaying it using VueJS on the frontend. The main issue I'm encountering is how t ...

What is the best approach to accessing a key within a deeply nested array in JavaScript that recursion cannot reach?

After hours of research, I have come across a perplexing issue that seems to have a simple solution. However, despite searching through various forums for help, I have reached an impasse. During my visit to an online React website, I stumbled upon the web ...

Issues with cross-site scripting in testacular E2E tests and Angular developments

I am currently in the process of developing a web application using Java on the server side and Angular for the front end. I am facing challenges while setting up end-to-end tests with testacular. The tests are failing due to what seems to be cross-site sc ...

Loading JavaScript in the background using Java and HtmlUnit

I am currently facing a challenge while navigating a website using HtmlUnit. This particular website adjusts certain buttons and displays or hides certain elements based on JavaScript events. For instance, there is a text input box along with a button th ...

Error: The function `map` cannot be applied to the components

My issue involves using the same components in two different locations, where one isn't functioning properly. The error is occurring in Board.js: TypeError: components.map is not a function const Board = () => { const [components, ...

I'm interested in learning the best way to insert the images from this JSON file into the corresponding div elements

I have completed developing a clone of an Instagram web page. Although I can retrieve data from the JSON file and insert it into the <img> tag, I am facing difficulty in displaying each image above its respective .below-image div with consistent spac ...

Guide to sending a response to an AJAX post request in Express with Node.js: Answered

For a project focused on practicing Node.js and jQuery Ajax, I'm working on a simple task. Essentially, I have an ajax post request that sends data to a Node.js server and waits for a response. On the server-side, there's code that processes this ...

What is the best way to exclude the bottom four rows when sorting with MatSort?

Is there a way for me to keep the last four rows fixed when sorting the table based on the column header? Here is an image of the table: table image <table mat-table [dataSource]="dataSourceMD" matSort (matSortChange)="getRowMaximoTable( ...

How can Jasmine be utilized to test JavaScript code that relies on the presence of a jQuery template?

My usual method for incorporating jquery templates into my html files is like this: <script id="some-template" type="text/x-jquery-tmpl"> The actual template content goes here... along with some data: {data} </script> After setting up the t ...

Locate the closest K points to the center of coordinates at (0, 0)

Given a list of coordinates, the task is to find the k closest coordinates to the origin. While I successfully calculated the distances between the points and the origin, determining the closest k points presented an issue. To solve this, I implemented lo ...

Changing the state variable upon clicking to display varying components

Being new to React, I am exploring how to load different components based on state variables. I am looking for a way for my handler to dynamically determine which state variable I am updating without explicitly passing the state name as a string. List of ...

Creating a new row dynamically in reactable is a useful feature that can enhance the

My goal is to add a new row when clicking on an accordion, specifically while expanding using reactable. I have included the expected outcome below. I have displayed structured data in a table using Tr and Td from reactable, but I am uncertain how to add t ...

The input box fails to show larger values on the user's page

Show me the biggest number that the user enters in an input box and then display it back to them. I need some improvements to my code, ideally making it possible with just one input box instead of two. <!DOCTYPE html> <html la ...

Protected knockout observable

Incorporating the protected observable into my code has been a goal of mine, so I stumbled upon this helpful tutorial: HERE While experimenting with the demo on the website, I encountered an interesting scenario: Initially, click the edit button for a ...

Tips for formatting input boxes on the client side

Q: How can I format my textbox so that when a user enters a number, such as one, it will be displayed as 0000001? The goal is to have any number entered be shown in 7-digit format. ...