What is the best method for looping through all text fields in Selenium?

My challenge involves a group of text fields all sharing the same class names. Here is the HTML code:

Each text field has identical class names, and I am attempting to automate inputting values into them by using the sendKeys method in Selenium. For this task, I am utilizing JavaScript (chai, mocha, node) to execute my automation.


             <div>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1">adad</textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1">adadad</textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
                 <textarea class="form-control textarea-multi" name="191_table_1"></textarea>
              </div>

This was my approach: I attempted to use findElements by className and iterate through each one to fill out the text fields:

describe('complete text fields',function(){
        it('fill all the text fields',function(done){
            driver.findElements(By.css("input[type=\'form-control textarea-multi\']")).then(function(texts){
                console.log("got the list of texts");
                texts.forEach(function(textField){
                    console.log("sending keys for each of the text field");
                    textField.sendKeys("test");
                    count = Number(count) + 1;
                    console.log(count);
                    if(count === 6) {
                        done();
                    }
                });
            });
        });
    });

However, this process fails with a timeout error (Error: Timeout of 15000ms exceeded). Any assistance would be highly appreciated. Thank you in advance.

Answer №1

Here are some suggestions:

By.css(".form-control.textarea-multi")
By.xpath("//*[@class='form-control textarea-multi"]

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 best way to load CSS and JS files in a Spring Boot WebFlux

I am currently exploring a spring boot webflux project. Successfully rendered static HTML using Thymeleaf. Added a login page with CSS and JS, but encountered issues with rendering them in the HTML. The browser tools showed 404 errors for CSS and JS file ...

Python Selenium: How to interact with an element nested within multiple HTML tags

Currently, I am working on automating a website using selenium webdriver in Python. However, I have encountered an issue when trying to click on a specific tag. The website that I am attempting to automate is quite old and contains numerous iframes and &l ...

How can I retrieve text adjacent to a checked input checkbox by using JQuery (or JavaScript)?

Here is the HTML block under consideration: <div class"radioGroup"> <input type="radio" value="0"> This option is NOT selected <input type="radio" value="1" checked = "checked" > This option is selected <inpu ...

Modifying an object's attribute in React.js by toggling a checkbox

As I delve into learning React, I am constructing a straightforward todo list. Here's the object contained within my initialState: getInitialState:function(){ return { items: [ { text:"Buy Fish", ...

Utilize a ParameterizedTest to test localization bundles

I'm looking for a way to implement localization directly in order to run a test multiple times through a parameterizedTest. How can I use the Strings from the ValueSource as String parameters of the test, and then convert them into ResourceBundles tha ...

What is the best way to hide a div containing a ul list when all <li> elements within it have the display property set to none

Having an issue with my search feature. I have 6 different categories as shown below. When searching for something, I want the category box with no results to be hidden - all li elements should have display: none properties. <div class="category"> ...

Swap out AJAX following a successful retrieval and when managing errors

I currently have a basic AJAX load function set up to load a specific URL: <div id="load"> <h1 id="status">Loading...</h1> </div> <script type="text/javascript"> $(document).ready(function(){ $.ajaxSetup({cache: false}); var ...

Is there a way to troubleshoot and improve my Discord bot's kick functionality?

I'm having an issue with my code. When I type in the command "exp kick @user being toxic", it doesn't do anything. It seems to be ignoring my command. Here is the code snippet that I'm using: client.on("message", message => { var comm ...

A critical issue occurred: array length is invalid. The attempt to include EJS in the template failed due to

Currently, I am attempting to loop through my JSON data using EJS from Node/Express. However, I need to insert a different pin into the flexbox when it reaches the 6th iteration. Whenever I try to implement this logic, I encounter a severe error that disr ...

What is the correct way to execute a POST request?

Currently tackling a basic API project. Managed to nail the GET & DELETE requests, but the POST request is giving me a hard time. I'm almost positive it's a beginner mistake, but I can't seem to figure out the logic here. This specific file ...

Learning to utilize regex patterns in substitution tasks is an essential concept in programming

I need help with decoding a mysterious message: ********is******ri****f******s**d******s****du****? The message seems to have been encoded using a complex search pattern: ([y\s]|[wh]|[apl]|[oo]|[mb])* Along with a replacement pattern: *$2* Wou ...

Is JavaScript ES6 reassigning or just a parameter?

Could someone provide an explanation for what's going on here? I am familiar with express middleware, but I'm interested in understanding the syntax. I grasp the ES6 syntax for mustBeLoggedIn, but I'm unsure about the purpose of const forbi ...

What options do I have for sorting through my inventory using the search feature?

Having some trouble setting up isotope filtering on my search bar. I have managed to get the Isotope function working on checkboxes, but for some reason, my search bar isn't functioning as expected. I found a solution online for filtering results bas ...

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

The function Promise.all is providing an array filled with undefined values and resolves prematurely before completing its task

I am encountering an issue with a function that is returning an Array filled with undefined values. Below is the code segment in question: classMethods.getQueries = function(models, dbId, dateStart, dateEnd) { return new Promise(function(resolve, reject ...

Is there a method to verify the presence of a message event listener already?

Is there a method to determine if a message event listener is already in place? I am trying to accomplish something similar to this: if(noMessageEventListenerExists) { globalThis.addEventListener('message', async function (data) {}) } I have ...

Error: An unexpected identifier was encountered while declaring a class attribute

class Data { title: string; fields: string[] = []; parent: string; attributes: any = {}; } Can someone help me out here? I'm encountering an issue. I am running node v14.17.0 This is the error message I'm seeing: title: string; SyntaxE ...

Parsing a JSON object in JavaScript: A step-by-step guide

Looking for assistance on how to parse the JSON object below: { "info": [ { "systemIp": "192.168.1.1", "status": "done 956" }, { "systemIp": "192.153.1.1", "status": "done" } ] } Does anyone have a solution using Javascript or jQuery? The desired output ...

Bookmarklet for Resetting CSS StylesIn this bookmarklet, you

I'm attempting to attach a new <div> element with custom content using a bookmarklet and apply inline CSS. However, the issue I am facing is that the styles from the parent page are interfering with my div. What would be the best approach to en ...

Stop the form from submitting when the enter key is pressed using VueJS and Semantic UI

After spending the past two days searching for a solution to this persistent issue, none of the suggested remedies have proven effective so far. My form's HTML structure is as follows: <form id="quote_form" action="" method="get" class="ui large ...