Managing window popups using WDIO - tips and tricks

Having some trouble handling a facebook auth dialog popup through webdriverio. Struggling to target the email and password fields for the facebook signup process.

Below is the code in question:

it('redirects after signup', () => {
    browser.url('/');

    const mainTab = browser.getCurrentTabId();
    browser.waitForExist('[data-test="facebook-login-button"]');
    browser.click('[data-test="facebook-login-button"]');

    // fb login form
    browser.waitForExist('#email');
    browser.setValue('#email', this.fbAccount.email);
    browser.setValue('#pass', this.fbAccount.password);
    browser.click('input[type="submit"]');

    // fb login authorization
    browser.waitForExist('button[type="submit"]');
    browser.click('button[type="submit"]');

    browser.switchTab(mainTab);
    browser.waitForExist('[data-test="intro-title"]');
});

Attempted to wait until the tab opens with the following code:

browser.waitUntil(() => browser.getUrl().indexOf('facebook.com') > -1);

Also attempted switching tabs more explicitly like so:

browser.switchTab(   
 browser.windowHandles().value[browser.windowHandles().value.length]
);

However, all of these variations lead to browser.waitForExist('#email'); timing out and not finding the email input after 30 seconds. The popup does open and is focused, but webdriver or selenium can't locate the required element even when I try manually clicking on it.

Any advice on how to handle this scenario correctly? Open to any recommendations on making this test successful.

Answer №1

In order to ensure success, it is essential to locate the correct window handle instead of assuming that the first or last one will suffice. While you can't guarantee which window handle is needed, you can at least narrow down the possibilities.

Prior to filling out the Facebook login form code, I included the following snippet:

// wait for popup
browser.waitUntil(() => browser.windowHandles().value.length > 1);
const popupWindow = browser.windowHandles().value.filter((handle) => handle !== mainTab)[0];
browser.switchTab(popupWindow);

This approach ensured that I was handling the appropriate windowHandle before proceeding further. Selecting either the first or last window handle consistently proved unsuccessful for me.

Please note: when using WDIO 5, remember to utilize getWindowHandle.

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

html5-jquery checkbox change event not firing

I successfully implemented an on/off switch using the method outlined in for HTML5. The functionality of the switch itself is working perfectly - click on it to toggle between states and query the checked state of the input/checkbox. However, I am facing ...

Executing a click using browser.execute_script in Selenium with Python versus a standard click command

As I was trying to interact with a webpage element, I initially used the following code: WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#styleguide-v2 > div.banner-container > a:nth-child(2)"))) However, ...

Angular - Implementing an Object Mapping Feature

Looking to dynamically generate parameter objects in Angular with a structure like this: [ password: {type: 'String', required: true, value: 'apassword'}, someRandomParam: {type: 'Integer', required: false, value:3} ] ...

When would you recommend setting localStorage in an Angular application?

In my EmployeesComponent, I have a list of employees with buttons for "Education Overview" and "Salary Overview" for each record. Clicking on an overview button takes me to the OverviewComponent, which then loads either the salary or education component. B ...

Embarking on the GSAP journey

I'm attempting my first animation using GSAP, but no matter what I try, nothing seems to be working. I've even tried using example code without success. Within my PHP file, I have the following code snippet: <head> <script src="https:/ ...

Making an Ajax request to trigger a method within a controller

Here is the code snippet I wrote: $(function () { $("input#Submit1").on('click', function () { $.ajax({ url: 'Home/GetPort', method: 'GET' }); alert("test") ...

Utilizing Ajax to dynamically generate unique ID's for multiple checkboxes

I have been working on a website that is almost completed, however, I have come across a new task where I need to select check-boxes in order to archive news items or "blog posts". The concept is to have a check-box next to each blog post and by checking ...

The method to automatically load the default profile on Selenium once Chrome is already running

After researching on this question (How to load default profile in Chrome using Python Selenium Webdriver?), I have come across a code snippet that works perfectly as long as Chrome is not already open; otherwise, it throws an error. from selenium import w ...

Updating a section of a webpage using jQuery Mobile

I'm currently facing an issue with modifying a specific section of my webpage. Although this problem has been discussed before, I haven't found a satisfactory solution yet. The element in red on the page needs to change dynamically based on the ...

The arrow icon for selecting input in Material Dashboard React is missing

Source Code View Result Why is the arrow icon not visible when viewing the select like this? I am using "@mui/material": "^5.8.6". Can someone please help me with this? <Box sx={{ width: "auto" }}> <FormControl fullWidth> ...

Is there a way I can link a variable to a URL for an image?

Creating v-chip objects with dynamic variable names and images is causing an issue. The image source string depends on the name provided, but when I bind the name to the source string, the image fails to load. Despite trying solutions from a similar questi ...

Encountering an error in React Native: Unable to access property 'length' as it is

Currently, I am working on developing a registration application and I have encountered some issues in the final phases when attempting to submit the new data to the server. Below is the script I am using: import React from 'react'; import React ...

Use Selenium in Python to automate scrolling to the bottom of the page

I am currently utilizing Selenium with Python to gather a list of doctors from this particular website. I have opted for the Specialty option to retrieve the results. The way in which the results are presented is similar to a Twitter feed, where they load ...

What is the process for modifying the headers of a post request in Express when

I have a Node/Express application and I'm looking to incorporate an image upload feature into an order form. While I can successfully use the action link in the HTML form to perform a POST request, I also want my JavaScript file associated with this ...

Step-by-step guide on creating a login functionality in Node using the Mean.io stack

I'm currently working on a web app using the MEAN.io stack. I have completed the frontend part with HTML, CSS, and AngularJS along with some logic. Now, I am looking to implement server-side login functionality, but I'm unsure where to begin sinc ...

Guide to making a language selection wrapper using a gist script

Currently, I have a Gist file that is written in various languages but all serve the same purpose. As a result, I am interested in developing a language selection feature similar to what is found in the Google docs documentation. https://i.stack.imgur.com ...

How to retrieve the value of an observable from a regular JavaScript array in Knockout JS?

Context In my project, I am working with a plain JavaScript array that starts off empty but gets populated with Knockout observables later on. These values are numbers and I need to compare them with values in another Knockout observable array. The issue ...

Python script for automating Steam Community Market listings with Selenium

I am in the process of creating a software that can access a Steam Community page and extract the first value from the price table. I need to be able to retrieve this value dynamically, as it will change frequently. I want to accomplish this without using ...

React Native automatically triggers the onPress event when using withNavigation

It seems that onPress should only be triggered by a touch event. Initially, this was the case, but when using withNavigation in a screen outside of the StackNavigator, onPress appears to render automatically. HomeScreen.js function mapStateToProps(state) ...

I am having trouble getting the Audio Code (a very basic code) to function properly

<audio id="myAudio" src="Avengers.mp3" type="audio/mpeg"></audio> <script> window.onload = function(){ document.getElementById('myAudio').play() } </script> Recently experimenting with some code in NotePad, a friend had ...