Having trouble changing windows with WebdriverIO (Selenium)?

Currently experiencing an issue with switching between different browser tabs.

The code in my test class is as follows:

describe('Validate tab switching functionality', () => {
    beforeEach(function() {
        browser.url("https://duckduckgo.com") 
      });
    it('Switch tab', () => {
        browser.newWindow('https://webdriver.io')
        browser.switchToWindow('DuckDuckGo — Privacy, simplified.');
    })
})

I keep encountering the following exception:

[0-0] 2019-07-24T10:22:26.116Z ERROR webdriver: Request failed due to Error: no such window
  (Session info: chrome=75.0.3770.142)
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64)
    at getErrorFromResponseBody (C:\Users\Gianni Bruno\Desktop\webdriverio-v5\node_modules\webdriver\build\utils.js:371:10)
    at Request._callback (C:\Users\Gianni Bruno\Desktop\webdriverio-v5\node_modules\webdriver\build\request.js:120:64)
    at Request.self.callback (C:\Users\Gianni Bruno\Desktop\webdriverio-v5\node_modules\request\request.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at Request.<anonymous> (C:\Users\Gianni Bruno\Desktop\webdriverio-v5\node_modules\request\request.js:1161:10)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at IncomingMessage.<anonymous> (C:\Users\Gianni Bruno\Desktop\webdriverio-v5\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:286:20)
[0-0] Error in "Validate switching of tabs Switch tabs"
no such window
  (Session info: chrome=75.0.3770.142)
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64)

Your assistance would be greatly appreciated.

Answer №1

For enhanced functionality, consider using the switchWindow method in place of the switchToWindow method. Additional information can be found here.

describe('Confirm tab switching', () => {
  beforeEach(function() {
    browser.url("https://google.com") 
  });

  it('Switch tabs', () => {
    browser.newWindow('https://selenium.dev')
    browser.switchWindow('Google');
  })
})

Answer №2

Enhance your automation script with the browser.switchWindow(urlOrTitleToMatch) function.

describe('Verify tab switching functionality', () => {
beforeEach(function() {
    browser.url("https://duckduckgo.com") 
  });
it('Switch to a new tab', () => {
    browser.newWindow('https://webdriver.io')
    browser.switchWindow('DuckDuckGo — Privacy, simplified.');
})

})

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

Using React JS, you can easily display only the result without showing the button by implementing a

I am encountering a few challenges. Any assistance would be greatly appreciated. The main issue I'm facing is with a button that is meant to display an array of options received through props from the parent component. However, when I click on the ...

Error loading OBJ file in Three JS OBJLoader module

i'm having trouble importing an obj file using OBJLoader The obj file looks like this - Obj Image https://i.sstatic.net/HPdR8.png But when imported into Three.js, it looks like this - Obj in Three.js https://i.sstatic.net/CoSYz.png The obj file ...

Retrieve text based on index across different classes, xpaths, and css selectors

When scraping HTML, I noticed that there are multiple classes with the same name. The structure looks something like this: <span aria-hidden="true" class="v-align-middle social-details-social-counts__reactions-count">56</span&g ...

Dealing with a TimeoutException error in Python Selenium despite utilizing a wait until clickable function, along with handling the

Recently, my selenium webdriver has been crashing repeatedly due to a TimeoutException that reads: "timeout: Timed out receiving message from renderer: 298.972." The issue arises when the cookies pop up opens, but the script fails to click on it consiste ...

Loop through the JSON object at a depth of three levels

Can someone please help me with this issue that's been bothering me? I'm currently working with Facebook's Graph API to access data. I need to find out how to retrieve the application name. { "data": [ { "messag ...

Implementing a functionality in Angular.js to automatically populate an input field when a checkbox is checked

My goal is to set the respective input field to a specific value when a checkbox is checked. Below is an example of what I am trying to achieve. <label class="checkbox-inline"> <input type="checkbox" name="favoriteColors"> Five </label& ...

Combining outcomes from two separate jQuery AJAX requests and implementing deferred/promise functionality

I am struggling to combine the outcomes of two jQuery AJAX requests. Despite reviewing similar questions here, none seem to provide a solution. Each ajax call (2 in total) has a success function that calls the createStatusView function and passes it the ...

Changing the name of a checkbox label using jQuery and JavaScript

I am struggling with dynamically creating checkboxes and setting the label names correctly. Setting the inner html value didn't work for me. What is the proper way to achieve this? source: <!DOCTYPE html> <html> <head> ...

Tests are not being executed by Nunit 3.00

My Nunit 3 seems to be having issues running tests, whereas everything works perfectly with version 2.64. Despite not encountering any errors, version 3 simply refuses to run the tests. The testing is being done using Selenium-C# and Appium. ...

html5sql - Struggling to establish a connection with my database

I recently started using html5sql.com for my html5 DB needs and I must say, it's a fantastic module! However, I've hit a roadblock. In my index.html/index.js file, I have set up my database and created tables in it. try { html5sql.open ...

Add the content of a JavaScript variable to a label without using any scripting

Is there a way to concatenate the value of a JavaScript variable with a label without utilizing jQuery? For example: Var global_message = "1234"; <label id="my-label">Test</label> I desire the concatenated value "Test1234" to be displayed o ...

Guide for preventing hours before the scheduled date and time with v-calendar

I am utilizing v-calendar to display the start date and time as well as end date and time in dateTime mode. My goal is to prevent the end date and time from being set before the start date and time. In order to achieve this, I have implemented the :min-dat ...

The functionality of jQuery code can be inconsistent at times, running smoothly

I'm facing confusion with my jQuery code! It works fine sometimes, but not always. I had a similar issue with CSS too, and I initially thought it was because of the web browser. However, the problem persists. JAVASCRIPT CODE $('.glyphicon-chevr ...

What is the method to retrieve the src element that includes the text "viewPdf"?

In the inspect element output, you will find the following snippet: <html> .... ..... <iframe id="g3GQfw" class="empPdfIFrame z-iframe" src="/emp/viewPdf? id=1236222&amp;PdfDataSource=viewEmpPdfDataSource" frameborder="0"></iframe> ...

Optimizing react onClick events to allow for multiple functions to be executed efficiently

I am currently developing a react button component that takes in one function as a prop to be run when the onClick event occurs. <Button onClick={() => console.log('hello')}> This translates to <button onClick={onClick}> Say hel ...

Adding shaders to a THREE.Object3D that has been loaded from a STLLoader can enhance the visual

I successfully loaded a model using THREE.STLLoader. var loader = new THREE.STLLoader(); loader.addEventListener('load', function(event) { var mesh = event.content; scene.add(mesh); }); loader.load('model/test.stl'); Now, I wa ...

Creating a 3-column grid in React using the map function is a simple and efficient way

Looking to arrange my cards in a specific grid pattern: [] [] [] [] [] [] [] [] [] ... ... Facing an issue with rendering items using the map function. I've attempted a solution, but it's not working as expected. To create a new row for every in ...

When webpack DllPlugin is utilized alongside bootstrap 4 beta, it leads to an Uncaught ReferenceError

Currently, I am utilizing DllPlugin in my development environment. However, once I introduce bootstrap into the build, it causes my vendor dll to break. Interestingly, if I comment out bootstrap, all other references work perfectly fine. Below is the relev ...

`How can I extract a JSON string from a URL using Javascript?`

Currently, I am attempting to retrieve a JSON string from the following URL: This URL displays the JSON location value as a string, an example of which is shown below: {"BMS":[{"id":"PR01","type":"prajurit","lat":"-6.253310","long":"107.156219"},{"id":"P ...

What is the reason for the hotel's Object _id not being saved in MongoDB?

Can you assist with troubleshooting this issue? This is the HotelRoom Module: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const HotelRoomSchema = new Schema({ name : { type : String, require : true ...