Guide to using sendKeys in selenium with nodejs to input text at the current cursor location

I've developed a script to add comments on Facebook posts. I can click on the comment box and see the cursor, however, I'm having trouble using the .sendKeys() method.

Below is my code snippet:

var commentBox = driver.findElement(By.xpath('//*[@id="addComment_'+this.postIdSlice+'"]/div/div[2]/div/div/div/div[1]/div'));
actions.mouseMove(commentBox).click().perform();
driver.sleep(2000);
actions.sendKeys("Hello").perform();

When I run it, the 'Hello' text doesn't get sent to the comment box. PS: The postIdSlice variable holds the post's ID, so that part is functioning correctly; my issue lies in inputting the string into the comment box.

Answer №1

To interact with the comment box, utilize Xpath to locate it and then apply ActionSequence for inputting text followed by pressing ENTER key.

let action = new webdriver.ActionSequence(driver);
    action.sendKeys("comment");
    action.sendKeys(Keys.ENTER);

action.perform()

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

unraveling JSON in Node.js

I am encountering an issue with accessing the 'column' in my JSON data below. I keep getting 'lowerdeck' as undefined. Can someone please assist me in resolving this problem? { "errorcode": "0", "xml": { "seat-map": { "lo ...

Accessing a particular level within a JSON object in Node.js

I'm dealing with a two level JSON structure {"Policy": { "Channel": "online", "Credit Score": "20000", "Car": [{ "Age": "28", ...

Encountering an Invalid Host header while connecting a domain name with a reactjs application

Currently, I am in the process of deploying a JS application (with the backend in nodejs and front-end in reactjs) on a hosting server. To ensure smooth operation, I have dockerized all components including the back end, front end, and database. As of now, ...

Top-notch beginner-friendly tutorials for Selenium Python bindings

As someone new to the field of automation, I am eager to learn python selenium. However, I am struggling to find the most suitable tutorials for beginners that will provide me with comprehensive knowledge. If you have any recommendations for the top tutor ...

Can express middleware be tailored for each individual handler within the same route path?

I am seeking to create distinct routes under an /api path with varying middleware handlers, each allowing for different authentication methods. My initial approach was to nest these API routes under separate instances of the Router object using Express: c ...

Automatically use JavaScript to send an email to my email address

I have a question I'm trying to solve: Is there a way to send myself an email notification (using a different address) when a specific event occurs in Javascript or Node.js? For example: if (100 > 90) { emailto="xxxxx.gmail.com" subject="It happ ...

Implementing virtual hosts and HTTPS encryption

Is it possible to configure vhosts on Express with https? This is my current code without SSL: var express = require('express'); var vhost = require('vhost'); var path = require('path'); var appOne = express(); var appTwo = ...

Is there a way to pinpoint the line number of a failed cucumber-js step while running through webdriver.io?

After upgrading from an ancient version of cucumber-js (4.2.1) to a more recent one (7.2.1), I am facing an issue where I can no longer determine the line in my feature file where a test is failing. My setup involves using cucumber with Webdriver.io (v7.7) ...

Having trouble with mongoose-paginate and react using material-ui's TablePagination component? Encountering issues where the second page onwards does not render after

I am still learning my way around React, and I believe there is a crucial component missing in this particular React setup. Any assistance leading to a solution will be greatly appreciated. The Functionality I'm Striving For Here - I aim to incorpora ...

I was surprised by how Await behaved in if-else statements, it was not what

let metadata = []; allNFTs.map(async (e) => { if (e.metadata) { metadata.push(JSON.parse(e.metadata).attributes); } else { let config = { method: "get", url: `http://localhost:3000/api/fetch ...

What are some methods to execute a line of code in the event that the button is not present within my IF statement

After receiving assistance from a member on this platform, I managed to get this code to function correctly: boolean clickMore = true; while(clickMore == true) { List<WebElement> button1 = driver.findElements(By ...

Calculate the time difference between the stroke of midnight on a specific date and the present moment using JavaScript, node.js, and

Looking for a way to determine if the current moment is less than 3 minutes after midnight of the next date using a JavaScript Date object (e.g. 09.08.2020 15.45). This condition should evaluate to true for times ranging from 09.09.2020 00:00 up until 09.0 ...

Establishing parameters in a Socket.io chatroom

I am encountering an issue when attempting to store information in the socket room variables. The error message I receive is: UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'host' of undefined This is the snippet of my code: io ...

In order to successfully build and run this project on Visual Studio 2022 for Mac, Node.js is an essential requirement

I encountered the following error while building a client cs-project: Error: Node.js is required to build and run this project. I have installed node using nvm on my Mac which node The above command returns /Users/***/.nvm/versions/node/v18.15.0/bin/nod ...

What is the reasoning behind including the node_modules folder in the npm package by default?

Typically, when you browse a module on npm, you won't find a node_modules directory. It's generally considered bad practice to upload your node_modules/ folder to npm. Instead, this directory is meant to be created and filled by the client when t ...

Executing a Selenium script in C# to select the radio button labeled as Yes

Can someone help me write an XPath for the 'Yes' label in green color on the UI image? I am new to automation and would appreciate any assistance. Below is my HTML code and UI snapshot: https://i.stack.imgur.com/affN5.png https://i.stack.imgur. ...

Utilizing the <slot> feature in Angular 5 for increased functionality

Currently, I am working on a single page application (SPA) where Vue framework has been utilized for development purposes. Front-End: Vue Back-End: NodeJs Within my application, there are other sub-modules built in Angular 4. I am looking to replicate th ...

Guide on configuring the AutoIt path in Python

I am encountering an issue while trying to automate file uploads using the AutoIt library in combination with Selenium and Python. When executing the code, I receive the following error message: from .autoit import options, properties, commands File &quo ...

The HTML table inexplicably displays a random comma out of nowhere

When working on my HTML table, I noticed that it was rendering a comma unexpectedly. I am using Nodemailer and SMTP Google server, and I suspect the issue lies within the HTML code. However, I am struggling to identify the exact problem. https://i.stack.i ...

Communication between the Node development server and the Spring Boot application was hindered by a Cross-Origin Request

Here is the breakdown of my current setup: Backend: Utilizing Spring Boot (Java) with an endpoint at :8088 Frontend: Running Vue on a Node development server exposed at :8080 On the frontend, I have reconfigured axios in a file named http-common.js to s ...