Choosing Frames within node.js

I am facing an issue with switching to nested frames in selenium-webdriver using node.js. Despite trying various approaches such as setting timeouts for page loading and frame switching, I am still encountering a NoSuchFrameError. This problem seems to be related to this question.

Here is the full HTML URL: here

<!DOCTYPE html>
<html>
<head>
<title>HTML Target Frames</title>
</head>


<frameset rows="16%,84%">
    <frame src="./framesHtml/top.htm" name="top_page" >
    <frameset cols="50%,50%">
        <frame src="./framesHtml/menu.htm" name="menu_page" >
        <frame src="./framesHtml/main.html" name="main_page" >
    </frameset>
</frameset>
</html>

Function for switching to main_page:

var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var chromePath = require('selenium-chromedriver').path;
var FrameHandler = require('../../JS-Selenium-Toolkit/src/FrameHandler');
var expect = require('chai').expect;

describe('FrameHandler', function () {
  it('Should pass if the set frame is main_page', function (done) {
    this.timeout(15000);

    var service = new chrome.ServiceBuilder(chromePath).build();
    chrome.setDefaultService(service);

    var chromeDriver = new webdriver.Builder()
        .withCapabilities(webdriver.Capabilities.chrome())
        .build();

    var frameHandler = new FrameHandler(chromeDriver);

    //check current frame name
    frameHandler.getCurrentFrameName(function (name) {
        console.log(name + ' current frame inside second function');
    });

  chromeDriver.get('http://orasi.github.io/Selenium-Java-Core/sites/unitTests/orasi/utils/frameHandler.html').then(function () {
    frameHandler.switchToFrame('top_page').then(function () {
        frameHandler.switchToFrame('main_page').then(function () {
            frameHandler.getCurrentFrameName(function (name) {
                console.log(name + ' this frame was switched to ');
                expect(name).to.equal('main_page');
                done();
            });
        });
     });
  });
 });
});

FrameHandler Object:

var webdriver = require('selenium-webdriver');

var FrameHandler = function (driver) {

    this.switchToFrame = function (name)
    {
            if (typeof name !== 'string' || name === '' || !name)
            {
                console.log('error');
            }
            else
            {
                console.log(this.getCurrentFrameName(function (name) {
                    console.log(name + ' this is the current frame before switch');
                }));

                console.log(name + ' switch to this frame');
                return driver.switchTo().frame(name);
            }
    };

    this.getCurrentFrameName = function (callback)
    {
        driver.executeScript('return self.name').then(function (name)
        {
            return callback(name);
        });
    };
};

module.exports = FrameHandler;

Answer №1

I have not personally verified this with your specific example, but the general consensus is that you cannot directly switch to a nested <frame> from the top-level. You must first switch into a parent <frame>.

In simpler terms, you need to go into 'top_page' and then into 'main_page'.

Check out the top answers at:

  • Unable to click with Selenium in nested frames
  • How to navigate a subframe inside a frameset using Selenium WebDriver?

Answer №2

During my extensive testing and experimentation with different drivers, I made a significant discovery - the chrome driver does not support nested framesets. Despite trying various approaches such as transitioning from the top_page to the menu_page and direct navigation to the menu_page, none of them yielded successful results. Exhausting all possible solutions, it wasn't until I switched to IE or Firefox that I was able to achieve the desired outcome. Removing the nested frameset from the HTML file and running the test using the chrome driver resulted in passing the test case effortlessly. This issue underscores a compatibility problem between nested framesets and the chrome driver, emphasizing the importance of finding a resolution as it could potentially impact automation processes relying on the chrome driver.

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

Verify the user's activity status in the MySQL database using Node.js by checking the timestamp of their last login

I have a query regarding user activity and deletion from the database. I need to determine when a user last logged in to see if their account is inactive. Unfortunately, I am unsure of how to tackle this task or check for the last login time. If anyone c ...

Streamline your Salesforce application by automating drop down selections with XPath using Selenium WebDriver

https://i.stack.imgur.com/Eg9jc.pngAn application has been developed in Salesforce with a dropdown box containing items built using the <li> tag. However, I am unsure how to select a specific item from this design. <div id="Department__cformContr ...

Inspect the json data to find a specific value and then determine the corresponding key associated with

I am currently working with JSON data retrieved from which I am storing in a variable. Despite my limited experience with JSON/JS, I have been unable to find a solution through online searches. Here is the code snippet: function checkMojang() { var moj ...

Issue C2039: 'IsNearDeath' cannot be found within 'Nan::Persistent<v8::Object,v8 ::NonCopyablePersistentTraits<T>>'

After updating my nodejs to v12.3.1, I encountered errors when attempting to execute npm install in my project directory. error C2059: syntax error: ')' (compiling source file ..\src\custo m_importer_bridge.cpp) error C2660: 'v8 ...

Tips for fetching a response after sending an ajax request using XMLHttpRequest

/* The following **frontend** function is executed to transmit a new post (in JSON) to the Node server */ addPost(postData) { const xhr = new XMLHttpRequest(); xhr.open('POST', `${process.env.REACT_APP_BACKEND}/posts`); xhr.setRe ...

Having trouble downloading on Mac, forget it

I am encountering permission issues while trying to install nodejs and npm (node package manager) using nvm (node version manager). To resolve this problem, I have decided to use nvm for the installation process. To find instructions on how to install nvm ...

What is the best way to test for node.js behavior during a graceful shutdown?

Behold the illustration of my smooth shutdown process: function shutdownHandler() { logger.debug(`Initiating shutdown for server running on port ${settings.port} with pid ${process.pid}`); server.close(() => { logger.debug(`Server running on p ...

Why is req.body empty in Node even when the form data is correctly POSTed in Angular?

Attempting to make a basic POST call to a RESTful API that was created, using Angular on the client-side, nodejs for the server, and mongodb+express+multer for the database. While testing the back-end with POSTman, everything appears to be working correct ...

Rendering views and templates in Node.js using EJS

I have a couple of queries regarding the render view functionality, Why does it not work as expected? When I place res.render inside if(error), the new site is not rendered and it remains on the current page. Another question I have is related to displayi ...

Experiencing difficulties while attempting to utilize Appium on Ubuntu, encountering a node.js:134 error

I installed nodejs by using the following command: sudo apt-get install -y nodejs Similarly, I installed appium with the command below: sudo npm install -g appium Despite the warning on the appium page advising against using sudo, I had to use it becau ...

Sending a link via email using Node.js and Express can be achieved by integrating nodemailer into

I need help with sending clickable links via email. Below is the code I am using: const data = { from: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdd0d8fdcedcd0cdd1d8ce93d0dcd4d1dac8d393d2cfda">[email protec ...

Using MongoDB and Pug/Jade templates with Google Maps API to display multiple markers in

I've been attempting to integrate map location data from my mongodb collection, but I've run into an issue where I can only access one piece of data at a time. I tried looping through the data both on the server-side and client-side to display it ...

Different ways in which a selenium script can be run

I've developed a selenium script using python 3. The script needs to run daily at 7AM for approximately 5 minutes. However, I don't want to keep my laptop running all the time just for this task. Can anyone suggest an alternative that is convenie ...

Avoid having Vue CLI delete all files in the dist folder

As I work on my Vue project, I am facing a challenge in syncing the dist folder with Git. Previously, this process ran smoothly when using webpack. However, after transitioning to @vue/cli and creating my project with vue create myProject instead of vue in ...

Error in navigating Node.js path

Within my server.js file, I have the following code: app.use(express.static(__dirname + '/public')); app.get('/', function(req, res){ res.sendFile('index.html'); }); app.get('/report', function(req, res){ ...

Comparing the keydown actions in protractor versus selenium

Protractor: 5.4.1 Selenium: 3.14 geckodriver: 0.23 browser: firefox Hello there, I'm encountering an error message "Failed: sendKeysToActiveElement" when running the code below browser.actions().keyDown(protractor.Key.CONTROL).click(elements).keyUp( ...

A guide on using tsc to build a local package

Unique Project Structure I have a unique monorepo structure (utilizing npm workspaces) that includes a directory called api. This api directory houses an express API written in typescript. Additionally, the api folder relies on a local package called @mya ...

Troubleshooting Nuxt and Express - breakpoints failing to activate

I'm starting to explore nuxt + express. I have the code from this link: https://github.com/nuxt/express, and it's working well with npm run dev. Now, I want to debug the API code. Inside users.js: import { Router } from 'express' var ...

Tips for capturing test outcomes utilizing Dataprovider in Selenium and storing them in an Excel sheet

I've been attempting to store the output of a calculator operation in an Excel spreadsheet, but I'm struggling to come up with a logical way to loop through the rows and columns depending on the number of test cases. (I hope that explanation make ...

Exploring the functionalities of the read and write stream in csv-parse

Hey everyone, I'm new here and feeling a bit confused about how to properly use readstream and writestream. Currently, I'm attempting this (using the library https://www.npmjs.com/package/csv-parse) fs.createReadStream(path.join(__dirname," ...