The value retrieved by GetElementByID is not being captured by the Textfield

Greetings, I have been working on automating a mobile application using Appium. Unfortunately, I encountered an issue where the .sendkeys method was not allowing me to edit a text field, so I decided to switch to a JavaScript method as shown below.

 driver.executeScript("document.getElementById('first-name').value = \"test\"");

The command above successfully fills the text field as intended. However, upon submitting the final form with the submit button, it indicates that the "First Name" has not been entered, suggesting that the value entered was not considered.

Example: https://i.sstatic.net/hy5JG.jpg

Does anyone have any ideas on what could be going wrong here?

Thank you

Answer №1

While I may not be an expert in appium, one suggestion to consider is using value = "'testing'" rather than

value = \"testing\"") as it appears that there is a slight deficiency of quotation marks.

Answer №2

After some diligent searching, I managed to uncover a viable fix:

              WebElement firstName = driver.findElementByXPath("//*[@id=\"first-name\"]");
              driver.executeScript("var element=arguments[0]; "
                          + "element.value='test';"
                          + "if (\"createEvent\" in document) "
                          + "{var evt = document.createEvent(\"HTMLEvents\");"
                          + "evt.initEvent(\"change\", false, true);"
                          + "arguments[0].dispatchEvent(evt);}"
                          + "else"
                          + "arguments[0].fireEvent(\"onchange\");", firstName); 

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

Tips on ensuring CSS is properly loaded on a Django HTML page

Despite numerous attempts, I cannot get my CSS to render properly on any of the HTML pages within a Django project. I've tried various solutions from Stack Overflow, such as adding the following code snippet: <link rel="stylesheet" href=& ...

Exploring the world of HTTP PUT requests in Angular 4.0

I have encountered an issue with a function I wrote for sending an http put request to update data. The function is not receiving any data: updateHuman(human: Human) { const url = `${this.url}/${human.id}`; const data = JSON.stringify(human); ...

Step-by-step guide on adding data to an arraylist using JavaScript

My ajax callback function receives a json object (arraylist parsed into json in another servlet) as a response, and then iterates through it. Ajax section: $.ajax({ url:'ServiceToFetchDocType', data: {" ...

The error message "Property 'id' is missing on type 'T'" is indicating the absence of the 'id' property in the

I am currently working on a React component that serves as a table and is designed to handle various types of data. The structure of the component is defined as follows: type SimpleTableProps<T> = { data: Array<T>; ... }; const SimpleTabl ...

Images mysteriously vanishing after importing the Bootstrap stylesheet

One of the features on my website is a page where, upon hovering over an image, an overlay appears with a caption. Below is the code for one such image: <div id="content"> <div class="mosaic-block fade"> <a targe ...

Add elements with jQuery and PHP

I am currently utilizing PHP code to call a series of images in the following block. Important: I have integrated "Advanced Custom Fields" plugin for Wordpress <?php // verify if the repeater field contains rows of data if( have_rows('upload-maso ...

Error encountered during installation of lite-server using `npm install lite-server --save-dev

Recently, I decided to give Node.js a try for the first time. After installing node.js, here is the version information: node -v v14.4.0 npm -v 6.14.5 I proceeded with the setup by creating a package.json file. However, when attempting to install lite-se ...

The closure of the Mongoose connection is triggered by the update of the node

Currently in the process of updating packages from a previous project and also upgrading Node. I have successfully upgraded from Node 12 to Node 18, moving up 2 versions at a time. Production appears to be functioning normally, however, in my development ...

Adjusting the background hue of the 'td' element within an ajax request

When I press a button, an ajax call is triggered below. In this call, I append 'td' elements with values to a table. Specifically, on the line ''</td><td>' + result[i].preRiskCategory +', I am attempting to change ...

What causes the Route to remain unchanged following an asynchronous function call in React

I am facing an issue with a code pattern that I believe should work, but for some reason, it is not functioning as expected. const MyComponent=()=>{ const history = useHistory(); function sleep(ms) { return new Promise(resolve => setTimeout(r ...

Can props.children be given a ref without any existing ref?

Consider this scenario... MainComponent.js <Wrapper> <p ref={React.createRef()}>{state.item1}</p> <p>{state.item2}</p> <p>{state.item3}</p> <p>{state.item4}</p> </Wr ...

I'm having trouble identifying the error in my Vue component that uses recursion. How can I pinpoint the

Currently, I am in the process of creating a questionnaire, and the JavaScript file containing the questions is a lengthy 4500 lines. Unfortunately, I am encountering a type error that is proving difficult to pinpoint within the code. Here is a link to the ...

Guide on looping through a collection of objects that have child objects and generating a new custom object

I am currently working with an object list retrieved from an API. The response looks something like this: { "1/22/20": { "new_daily_deaths": 0, "total_cases": 1, }, "1/23/20": { "new_deaths": 0 ...

JS Creating a Countdown Timer with an AJAX Request using a PHP Variable

The code snippet provided below calculates the time elapsed since the last customer registration in minutes and seconds. It retrieves the registration date variable from a separate PHP file. Is there a way to merge these two components to produce a real-t ...

Showing SQL query results on a Leaflet map

I am facing an issue with my leaflet map. I am trying to display an SQL query but it is not working as expected. I have stored the result in a JS variable as follows: <?php $connect = connect(); $req_ch = "SELECT json_build_object( 'type&apo ...

Within the HTMLDivElement.drop, the parent element now encapsulates the new child element

I've encountered a DOM exception that has me stuck. My issue involves div elements and a button - when the user clicks the button, a random div is selected and another div with a background-color class is appended to it. Essentially, clicking the butt ...

What is the method to convert Javascript values from pixels to percentages?

Is it possible to change the scrolltop value dynamically based on a percentage of the user's screen size? I've been trying to achieve this using JS but haven't had any luck. Here is a link to a codepen that showcases the issue: [link] (http ...

Exporting Data and Utilizing a Steady Data Table

I have incorporated the Fixed Data Grid into my latest project. https://facebook.github.io/fixed-data-table/example-sort.html My goal is to generate csv and pdf reports from the data displayed on the grid. Could you please advise me on how to export gri ...

There seems to be an issue with the DownloadDir functionality of the node-s3-client library, as

I am currently using a node s3 client library called 'node-s3-client' for syncing directories between S3 and my local server. As per the guidelines provided in the documentation, here is the code I have implemented: var s3 = require('s ...

What is the best way to specify option values for selection in AngularJS?

...while still maintaining the model bindings? I currently have a select menu set up like this: <select class="form-control" ng-model="activeTask" ng-options="task.title for task in tasks"> </select> When an option is selected, it displays s ...