Unable to input text into the input field using sendkeys or javascript in Internet Explorer 11

Currently, I am facing an issue while trying to input text into an input box using sendKeys or JavaScript. Even though I successfully see the value entered into the input field, upon clicking on the search button, I encounter an error message stating that the input field cannot be blank.

The HTML code snippet is as follows:

input id="inputMId" class="" type="text" data-bind="value: mId, onMFieldFocusOut: MId,css{datePicker:isMIdError()}" maxlength="15"
span class="validationMessage" style="display: none;"
span id="MErrorMessage" class="validationMessage" data-bind="text:mErrorMessage,visible:isVisibleMErrorMessage()" style="display: none;"



The approach I attempted is detailed in the following code block:

element.sendKeys("value") 


and

JavascriptExecutor js = (JavascriptExecutor)getDriver();
js.executeScript("document.getElementById('inputMId').value='"+testData.get("MId")+"';"); 



I am carrying out these actions on Internet Explorer 11 utilizing the Serenity framework.
While this implementation runs smoothly on Chrome, it seems to encounter issues on IE 11.

Answer №1

I recently experienced a similar issue with Internet Explorer and found a quick workaround that proved helpful:

  • Utilize the JavaScript executor to bring the element into view
  • Execute a SendKeys() action
  • Set focus on the text field
  • Remove focus (blur) from the element

I employ this method to simulate real user interactions.

I am curious about why a straightforward SendKeys() action works in Chrome but not in IE.

Answer №2

After trying different approaches, I found a solution that worked for me.

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable stringSelection = new StringSelection(myString);
clipboard.setContents(stringSelection, null);
element.click();
Robot robot;
try {
    robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_V);
} catch (AWTException ex) {
    ex.printStackTrace();
}

I cannot guarantee that this code will run successfully on Jenkins, but it is working perfectly on my local machine.

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

Is there a way to iterate through an array and transform the child JSON data into an observable array

Although this may be a common issue with many solutions available on Stack Overflow, my search so far has been unsuccessful. I have an array containing JSON strings. My goal is to loop through the array, convert the JSON into an observable array, and then ...

Wait for the Selenium test to continue only when a specific element is visible on

<img style="width: 640; height: 640;" id="img108686545" alt="Loading Word War..." src="www.something.com/anu.jpg"> Is there a way to detect when this particular element is visible on the page? The value of the "id" attributes keeps changing with eac ...

Resolving the issue of finding partial link class names in Selenium for restoration

My goal is to retrieve data for two classes named _2NQ7bVEP and _2NQ7bVEP entered. Unfortunately, I haven't been successful in using a single class name to fetch details for both classes. I have attempted to use xpath and the contains method, but ne ...

Execute JavaScript AJAX Request On Page Load

I am facing an issue with creating an onload event in which an AJAX function needs to be called and passed a value. The challenge lies in the fact that I have both my header and footer split into sections via PHP, therefore I cannot place it on the body ta ...

Exploring the use of arrays in Vue JS

Currently, I am working on a small project using VueJS 2.0, and it involves handling data that looks like this: {"data": [ { "id":8, "salutation":"Mr", "first_name":"Madhu", "last_name":"Kela", ...

"Combining two regular expression patterns within a single input field in HTML5

When validating an input, I am looking for a combination of alphabets, numbers, and a specific length range. I want to display separate error messages for each pattern. One error message should indicate that the input should contain only alphabets and numb ...

Able to display the value when printing it out, however when trying to set it in setState, it becomes

Within my form, there's a function that receives the value: _onChange(ev, option) { console.log(option.key) // Value of option key is 3 this.setState({ dropdownValue:option.key }) // Attempting to set state with 'undefined' as ...

Is it possible to "scroll up" when an editable element loses focus?

I want to create a contenteditable element that starts with a small width and expands as more content is added, eventually clipping the overflow. I also want this element to automatically scroll back to the beginning like a regular text box would. Setting ...

A tool designed to create a function that can fetch information from a JSON file

Currently, I am working on a function that accepts arguments and combines them to form a line for searching data in a JSON file. To accomplish this, I have initialized a variable for the readFileSync and then added the function's arguments to it in or ...

Sending optional data in Angular routesIn Angular, you can include additional

In my project utilizing angular 5, I have a lengthy routing file: const homeRoutes: Routes = [ { path: 'home', component: HomeComponent, children: [ { path: 'registration', component: RegistrationCompone ...

Implementing jQuery Rollovers for Independent Elements

Hello everyone, I'm a new user seeking assistance on the site! I am currently working on implementing buttons that reveal a table when rolled over and change their own image to a tab, but here lies the problem - I want the tab image to remain visible ...

React - the constructor binding issue with 'this' keyword

I am a beginner in React and I am learning through creating a simple test application. However, I am facing an issue with "this" binding. I set up this app package yesterday using "create-react-app", so all the necessary plugins including babel should be u ...

"Having trouble with ion-input functionality, but regular input is functioning without

Here is a code snippet that allows for multiple inputs in a list: <ion-content> <ion-list> <ion-item ng-repeat="player in players"> <ion-label>Player {{$index+1}}</ion-label> <input type="text" ng-mod ...

What is the best way to go about closing the jQuery Model popup window?

When a button on my view page is clicked, a pop-up modal appears. Now I am trying to figure out how to close that modal. Below is the code snippet: function openSirenModal() { var timeout; var progress; var status; $.modal({ contentAlign: 'cent ...

Cypress test never finishes when an unforeseen alert is triggered in the system during the test

When a web application unexpectedly throws an error using an alert box, the Cypress test becomes stuck indefinitely. The test will not complete or fail until the user manually closes the browser or clicks on the OK button within the alert box. https://i.s ...

The jQuery click event for sending data is not functioning properly, as it only updates the existing

I am currently working on implementing a click send function for my emoticon feature but I'm facing some issues with it. You can view the interactive demo I created on JSFiddle. The demo features four text areas and emoticons. When you click on an em ...

What is the best way to retrieve data from localStorage while using getServerSideProps?

I'm currently developing a next.js application and have successfully integrated JWT authentication. Each time a user requests data from the database, a middleware function is triggered to validate the req.body.token. If the token is valid, the server ...

"GM_openInTab in Userscript (Scriptish) not working properly, returning null value

There seems to be a problem with window.opener that I am facing. When I utilize window.open("url"), the child window will reference window.opener properly. However, if I use GM_openInTab instead, which is supposed to be the equivalent option for cross bro ...

Getting values for parameters using .attr("action") using JavaScript/jQuery - a beginner's guide

In my Ruby On Rails application, I have a form that is rendered like this: <%= form_tag myaction_path(item_id: item.id), { class: 'myaction', id: "myaction_#{item.id}", ...

Transferring the value of a variable from Block to Global Scope in FIRESTORE

I'm currently working on an App in Firebase, utilizing FireStore as my primary Database. Below is a snippet of code where I define a variable order and set it to a value of 1. Afterwards, I update the value to 4 and use console.log to verify. Everyt ...