The Webdriver sendKeys() function seems to be malfunctioning. Even attempting to use JavaScript as

Struggling to use WebDriver sendKeys() function to input text in a text field

View the HTML below:

<table class="gridtable" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true"    gwtcellbasedwidgetimpldispatchingblur="true" style="width: 100%;">
<thead>
<colgroup>
<tbody style="">
<tr class="GORM0XEDKD GORM0XEDME" onclick="">
   <td class="GORM0XEDJD GORM0XEDLD GORM0XEDMD GORM0XEDNE">
   <td class="GORM0XEDJD GORM0XEDLD GORM0XEDNE GORM0XEDGE">
       <div style="outline:none;" tabindex="0"></div>
   </td>
</tr>
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;">
</table>

XPath for the text field -
EmailTemplateEditorTemplateName=  By.xpath("//*[contains(@class,'GORM0XEDJD GORM0XEDLD  GORM0XEDNE GORM0XEDGE')]/div[1]");
  • We attempted the following options, all unsuccessful in entering text into the EmailTemplateEditorTemplateName text field

    1. driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).sendKeys("yahooo");
    
    2. this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
       WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
       JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
       rightexecutor.executeScript("arguments[0].setAttribute('value','yahoo')", tempname);
    
    3. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).sendKeys("yahoo").build().perform();
    
    4. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).click().sendKeys("yahoo").build().perform();
    
    5. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).click(Element).sendKeys("yahoo").build().perform();
    
  • The click() method is functioning correctly.

  • The getText() method surprisingly works for the same text field using the same XPath. String val=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).getText();
  • Only sendKeys() seems to be nonfunctional without any error being thrown.
  • Please provide assistance in inputting text into my text field.

Answer №1

Have you given this a shot:

After confirming that the Click function is working, try the following:

driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).click();
driver.switchTo().activeElement().sendKeys("Text");

Alternatively, you can attempt using the builder click and activeElement method as shown below:

builder.moveToElement(Element).click();
driver.switchTo().activeElement().sendKeys("Text");

Answer №2

If you're using Selenium/Webdriver, there isn't a direct way to set a value in a "div" tag.

One workaround is to utilize the JavascriptExecutor to set the innerHTML attribute like this:

this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
rightexecutor.executeScript("arguments[0].setAttribute('innerHTML','yahoo')", tempname);

Answer №3

Before troubleshooting further, it's important to check and ensure that you are using the latest version of the driver (Chrome or Firefox) that is compatible with your browser version. This simple step often resolves the issue quickly.

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

"if the condition is not met, the outcome will not be shown in the while

I have a looping structure that includes conditions for if, else if, and else. However, I have noticed that the else condition at the end of the loop is not being executed as expected. I am currently investigating why this might be happening. Here is the ...

Could not locate Webview on my actual Android device operating with version 5.1.1

Hybrid applications running on a real Android device with version 5.1.1 are experiencing issues with Webview when using Appium. Interestingly, the same setup works perfectly fine on an emulator with the same Android and Appium versions. ...

An undocumented finished status in Node.js

Currently diving into the world of node.js with the guidance of Node Cookbook. However, I've hit a roadblock when it comes to URL routing. Let's take a look at the code snippet provided in the book: var http = require('http'); var pat ...

Creating a custom color scheme for school events

I am currently studying coding in school and have just started my coding journey 3 months ago. This is my first post on a forum, so please be kind! I am encountering an issue with the drag function. For an extracurricular activity for school kids, I came ...

What is the best way to achieve a complete vertical rotation around an object using OrbitControls?

I want the rotation to continuously go around the object, but I'm having trouble setting the minPolarAngle and maxPolarAngle values (Setting them to (+-)Infinity causes the rotation to stop). Is it possible for the min and max PolarAngles in OrbitCon ...

Navigating the art of employing different fonts for a website

I am looking to incorporate the trainway font into my website, but I'm concerned that the user may not have it installed on their device. Is there a way to showcase text in a specific font without requiring the user to download and install it? Thank ...

Learn how to dynamically change a class name with JavaScript to alter the color of a navbar icon

I have little experience with javascript, but I want to make a change to my navbar icon. Currently, my navbar has a black background with a white navbar icon. As I scroll the page, the navbar background changes to white and the font color changes to black. ...

Having difficulty transferring images from the frontend to Cloudinary or any backend system

My goal is to upload an image from the frontend to Cloudinary for use as a profile picture in my app. Below is the code I am using: import { StyledInput, StyledLabel} from '../FormInputs/styles' import { useState } from 'react' import { ...

jQuery is not updating the div as expected

While typing out this question, I'm hoping to uncover a solution that has eluded me so far. However, just in case... About a year ago, I successfully implemented something similar on another website and went through the code meticulously. Surprisingl ...

Is it possible for two users with distinct roles to register using a shared email address?

Is it possible for both drivers and passengers to sign up using the same email address, allowing users to log in as either a driver or passenger, or even both with one email account? I have tried to do this but received an error message stating that the e ...

What does the blue digit in the Chrome Developer Console indicate?

I encountered a strange situation in JavaScript where I have a variable that I log to console.log, then increment it and log it again. The Chrome Dev Tools display the following result. This variable has shown some odd behavior, such as using the += opera ...

Discovering the worth in Meteor MongoDB

As someone who is new to web programming, I have been experimenting with Meteor and MongoDB lately. I have a form that sends data to MongoDB, and by using the query below, I was able to retrieve the most recent entry: database.findOne({}, {sort: {'t ...

Implementing scrollIntoView() method in Typescript

Currently, I am focused on automating an AngularJS application. Our go-to automation language is TypeScript. My aim is to scroll to a specific element and then click on it. var element = element(by.className('learn-link')); browser.driver.exec ...

Is there a way to retrieve the full class name with the help of Selenium's getAttribute method

class = "col-scope serialize" I encountered an issue in HTML where I have an element with a class name specified as above. However, when attempting to retrieve the class name using getAttribute("class"), only the value col-scope is ret ...

Separating the rules for development and production modes in the webpack configuration file

I'm currently in the process of working on a front-end project using HTML. Within my project, I have integrated the Webpack module bundler and am utilizing the image-webpack-loader package for image optimization. However, I've encountered an issu ...

Using Ajax, transmit an array from javascript to a php function

How can I send an array from JavaScript to PHP using AJAX? I'm not sure how to do this, especially when trying to send it to a PHP function like a controller class. Can someone please correct me if I'm wrong? Below is my current JavaScript code f ...

Reducing the key in MongoDB to a single value

I am trying to create a MapReduce program that counts the number of orders by clients within the last year, month, and week. var mapOrders = function() { var v_order = { order_date : this.dt_order ... }; emit(this.clientid, ...

JQuery is a powerful tool for stripping away styles from web

Is it possible to use JQuery to add the class "default" to a clicked <li> element and remove it from the others within a list in an HTML5 file? <ul id="ul-graellatab-list" class="tabs"> <li><a href="#" class="tabs_menu default"& ...

Sorting arrays in Javascript based on specific criteria

Let's imagine we have an array with all the 26 alphabet letters in random order. Now, what if I want a particular letter, like "M", to be the first in the list and then sort the rest of the alphabetically? How can this be achieved without having to sp ...

Exploring innovative methods for integrating dialog boxes in Chrome extensions?

Currently working on a Google Chrome extension and inquiring about the various choices for incorporating dialog boxes. I am looking for a solution that includes distinct head and body elements. The plan is to design custom-styled forms with jQuery. Are t ...