How to Verify if the Second Tab has Fully Loaded in Selenium Testing

Our current automation process involves using selenium. In order to open 2 URLs simultaneously, we have implemented the following approach: I use driver.get to load the first URL, which includes built-in synchronization for page loading. For the second window, I make use of the below code snippet -

String jscript="window.open('"+strURL+"')";
js.executeScript(jscript);
It functions as expected on Chrome, but in Edge, there is a delay in page loading. When attempting to switch to the other window using its title, it fails to locate the window.

If I incorporate a wait, the window loads and the switch operation works smoothly. However, I want to avoid hardcoding a specific wait time. How can I verify if the second window has fully loaded?

I tested the following method, but it results in a permission error on Edge -

String jscript="var win=window.open('"+strURL+"');win.onload=function(){}";
js.executeScript(jscript);

Answer №1

Test this method to verify if the page has loaded correctly.

wait.until( new Predicate<WebDriver>() {
            public boolean apply(WebDriver driver) {
                return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
            }
        }
    );

Give it a try and see if it works for you.

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

Transmit various data for a single checkbox via AJAX without the need to submit the form

I am facing an issue where I am creating a checkbox form in SQL and trying to send data by clicking on the checkbox, but the data is not being sent. Here is the loop for my checkboxes: <ul> <?php while($objResult = mysqli_fetch_array($objQue ...

Creating a type definition for a TypeScript InfiniteScroll component in React

I am currently in the process of developing an InfiniteScroll component to be used like this: import { getData } from 'api'; import { InfiniteScroll } from 'components'; export const App = () => ( <InfiniteScroll fetcher={page ...

Warning from Cytoscape.js: "The use of `label` for setting the width of a node is no longer supported. Please update your style settings for the node width." This message appears when attempting to create

I'm currently utilizing Cytoscape.js for rendering a dagre layout graph. When it comes to styling the node, I am using the property width: label in the code snippet below: const cy = cytoscape({ container: document.getElementById('cyGraph&apo ...

The jQuery plugin embedded in the Joomla 3.2 module fails to load or function properly

Seeking help with a JavaScript issue on my Joomla website. I'm not an expert, so please bear with me. I am using a regular plugin (not a Joomla specific one) to display my portfolio. It should work like this: ... black.html This is how it shouldn&a ...

What is the best way to use jQuery to emphasize specific choices within an HTML select element?

Seeking help with jQuery and RegEx in JavaScript for selecting specific options in an HTML select list. var ddl = $($get('<%= someddl.ClientID %>')); Is there a way to utilize the .each() function for this task? For Instance: <select i ...

Ensure that an object is within the frustum by utilizing THREE.js

I've been experimenting with Three.js and have a canvas that I want to use as a GUI. To achieve this, I need to check if an object is within the camera's frustum. Here is my current code snippet: camera.updateMatrix(); camera.updateMatrixWorld() ...

Modify the status of the variable specified within the ng-repeat loop from the controller perspective

Is it possible to modify the value of a variable declared in ng-repeat from the controller? I am attempting to set an initial value for a basic variable called "opened" which is used for toggling within an ng-repeat, directly inside the controller. <d ...

Tips for sending functions from client to server in Node.js

I'm working with this code snippet: const http = require('http'); const fs = require('fs'); const handleRequest = (request, response) => { response.writeHead(200, { 'Content-Type': 'text/html' ...

Conceal a division based on its numerical position

I'm having trouble figuring out how to hide multiple divs based on an index that I receive. The code snippet below hides only the first div with the id "medicalCard", but there could be more than one div with this id. document.getElementById("medical ...

What strategies can be used to efficiently perform Asynchronous Operations on a high volume of rows in a particular database table?

I am looking to perform Asynchronous Operations on every row of a specific database table, which could potentially contain 500,000, 600,000, or even more rows. My initial approach was: router.get('/users', async (req, res) => { const users = ...

What is the method for applying multiple criteria to filter an array in Vuejs?

const app = new Vue({ el: '#app', data: { search: '', itemsList: [], isLoaded: false, selectNum: status, userList: [{ id: 1, name: "Prem", status: "ok" }, { id: 2, ...

What is the process for incorporating SQL into a JavaScript function?

I'm having trouble getting user input into my database. I have a functional block of SQL code that should insert the data, but I keep encountering "undefined" errors when running it. Here is the SQL code in question: <?php require 'creationli ...

After resizing the window in jQuery, the scroll to section functionality does not behave as anticipated

My scroll function is not working properly after window resize. Here's how I want it to work: I resize the window. After resizing, when I click a specific menu item, the window should scroll to the section corresponding to that item with an offs ...

What is the reason for being unable to convert a function expression into a string?

Can you explain why the following code doesn't generate any output? console.log(JSON.stringify(function(){console.log('foobar');})); ...

Issue: unable to spawn process due to missing file or command (Snapchat NPM) in NodeJS environment

Every time I start my app, I encounter the following error: events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:980:11) at Process.ChildProcess._handle.onexit ...

Issues with AngularJS Filters malfunctioning

After watching some AngularJS videos and attempting to apply a filter to a list of bookmark categories, I'm having trouble loading the main content. At the moment, I haven't implemented views in my code and would like it to remain view-less for n ...

The email sending feature of the ajax jquery form has unexpectedly ceased functioning

I'm encountering an issue with a form that was previously able to send emails from the server, but suddenly stopped working. I'm having trouble identifying the cause of the problem. Interestingly, when I use the form without ajax, the email funct ...

Issues with asynchronous JavaScript and XML (AJAX) integration within JavaServer Pages (

I am encountering an issue with my code. When I run the project on localhost:\8081, everything works fine. However, when I upload it to a free host, it does not run properly. run not run Here is the AJAX code snippet: $(document).ready(function(){ ...

Guide to using Angular $resource to pass query parameter array

My goal is to implement a feature that allows users to be searched based on multiple tags (an array of tags) using the specified structure: GET '/tags/users?tag[]=test&tag[]=sample' I have managed to make this work on my node server and hav ...

What could be causing my Angular code to submit back unexpectedly?

My goal is to make an initial call to the database to populate some dropdowns, after which all actions are done through AJAX. However, whenever I click a button on the page, it seems to be posting back and calling the function that fetches dropdown values ...