Error message: Element is not able to receive focus due to an

Here is the code snippet for the input field:

<span ng-if="cell.state != 'edit_mode'" class="ng-scope">
    <span ng-class="{'with-right-padding' : cell.input_type === 'auto_complete'}" class="value-cell ng-binding">10        </span>
    <!-- ngIf: cell.valid === false && server_side_errors_present -->
</span>

The steps I followed are as follows:

//click on the field
element(by.xpath("//div[@class='animate']/div/div[2]/span[2]/section/div/div/section/div/div/div/span/section/div[2]/div/div/section/div[2]/section[1]/table/tbody[1]/tr[4]/td[3]/span/span[1]/span")).click();
//enter the value
element(by.xpath("//div[@class='animate']/div/div[2]/span[2]/section/div/div/section/div/div/div/span/section/div[2]/div/div/section/div[2]/section[1]/table/tbody[1]/tr[4]/td[3]/span/span[1]/span")).sendKeys("10");

The issue I encountered is that while the click event works, the send keys action does not.

Below is the error message I received:

Failures:
1) Customer Add a estimate
  Message:
    Failed: unknown error: cannot focus element
      (Session info: chrome=48.0.2564.109)
      (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 x86_64) (WARNING: The server did not provide any stacktrace information)
    // More detailed error information

  Stack:
    UnknownError: unknown error: cannot focus element
      (Session info: chrome=48.0.2564.109)
      (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 x86_64) (WARNING: The server did not provide any stacktrace information)
    // More detailed error information

If anyone has a solution to this problem, please share it with me.

Answer №1

var item = driver.findElement(By.xpath("//div[@class='animate']/div/div[2]/span[2]/section/div/div/section/div/div/div/span/section/div[2]/div/div/section/div[2]/section[1]/table/tbody[1]/tr[4]/td[3]/span/span[1]/span"))
driver.executeScript("arguments[0].setAttribute('value', arguments[1])", item, '10');

This solution could work for you. It involves using the execute script function provided by selenium webdriver. If this approach doesn't yield results, I recommend trying a different method to test the field instead of relying solely on xpath. The issue might lie in accurately targeting the desired field.

Answer №2

The previous solution utilizing javascript may encounter issues if there are event handlers associated with the input or its parent element, particularly when dealing with type-ahead controls.

To address this issue, we can utilize Selenium Actions:

Actions actionBuilder = new Actions(webdriver);
actionBuilder.moveToElement(webelement);
actionBuilder.click();
actionBuilder.sendKeys("<your value>");
actionBuilder.build().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

Encountered an issue with a module not being found while trying to install a published React component library that is built using Rollup. The error message states:

In my latest project, I have developed a React component library called '@b/b-core' and used Rollup for building and publishing to the repository. When trying to install the library in a React app, an issue arises where it shows Module not found: ...

Javascript functions fail to execute as intended

I have a project called calc, which includes various functions such as init. Within this project, there are three buttons that I am adding to the div using jquery. When a user clicks on any of these buttons, it should trigger the inputs function. Based on ...

How to trigger a function across various controllers in AngularJS

We're in the process of creating an app using phonegap onsen and angularJS. Attempting to invoke a function from a different controller has been challenging. Despite following various documentation such as this Unfortunately, it's not working f ...

Can I keep using ng-repeat multiple times in my code?

Working on a AngularJS application that involves handling a complex JSON file with multiple nested arrays and objects. My query is: Is it appropriate to use ng-repeat repeatedly for accessing the data from the JSON? <div ng-repeat="parent in parents"&g ...

Axios sending a 400 Bad Request to Django due to a missing required field

I'm having issues sending a POST request from my React frontend using Axios. import axios from 'axios' axios.post('http://server:port/auth/login', { username: 'admin', password: 'MY_PASSWORD', }, { ...

Why is this regular expression failing to match German words?

I am attempting to separate the words in the following sentence and enclose them in individual span elements. <p class="german_p big">Das ist ein schönes Armband</p> I came across this: How to get a word under cursor using JavaScript? $(&ap ...

Having trouble getting the JQuery Tipsy tooltip to display correctly with D3.js circles?

Below is the d3.js code that I have used: var circles = vis.selectAll("circle").data(data) circles .enter() .append("svg:circle") .attr("stroke", "black") .attr("cx", function (d) { return xRange(d.year); }) ...

Encountered an error while loading resource: server returned a 500 status (Internal Server Error) - A NodeJs Express and MongoDB Web Application hit a snag

I am currently in the process of developing a web application using NodeJS Express and MongoDB. However, I have encountered an issue while attempting to implement AJAX functionality to load and display comments on the post page. The "post-detail" page is ...

Step-by-Step Guide on Retrieving Filtered Data using React Context API

Currently, I am in the process of developing a dashboard application using React.js, React Context API, and ApexCharts. The app will visualize a 1000-length JSON data on 7-8 different charts, along with 6-7 variable filters. Overview of the App Structure: ...

Calculate the worth of a specific item within an array of objects and save the outcome as a new attribute

I am attempting to calculate the value in each element and then create a new element called "Count". Rule: Count the quantity if the next element has the same "Quantity" value, then add the total to a new element named "Count". I have tried implementing th ...

Only include unique objects in the array based on a common property

I am currently working with the following array: [ {name: "Mike", code: "ABC123"}, {name: "Sarah", code: "DEF456"}, {name: "John", code: "GHI789"}, {name: "Jane", code: "JKL01 ...

Seeking assistance with jQuery/AJAX syntax, any pointers

In my project, I have created two forms, one called 'table' and the other called 'fields'. The 'fields' form is designed to display options based on the selection made in the 'table' form, using an Ajax request. I ha ...

Can RemoteWebDriver be transformed into an AndroidDriver in any way?

1. Setting up a page by declaring the driver as RemoteDriver. 2. Invoking a function where I'm once again specifying the driver as RemoteDriver. 3. Executing a test with the driver declared as RemoteDriver. 4. Attempting to access the AppiumDriver met ...

JS await function does not wait for the completion of the request

https://i.sstatic.net/weCy0.png async function updateData(){ let stickTimes = []; await request(terryRink, function (err, res, body) { if(err) { console.log(err, "error occurred while hitting URL"); } else { le ...

Oops! There seems to be a problem with the Node.js App. The MongooseError is indicating that the parameter `uri` in the `openUri()` function should be a string,

I've encountered an issue with my Next.js app involving MongoDB that I've been struggling to resolve. Hoping someone here can provide some insight and help me out. This is quite crucial for my project. First, I'll share the code from my serv ...

"Unfortunately, Azure Web Static Apps do not have the capability to access .env files that are prefixed with NEXT

Suppose I have an .env file set up like this: NEXT_PUBLIC_API_BASE_PATH = value1 While this .env is functioning correctly in my local environment, once deployed to Azure Web Static Apps and added to the configurationhttps://i.sstatic.net/eqiYn.png My app ...

Encountered error 501 when utilizing AngularJS $http.post due to an unsupported method ('POST')

Thank you in advance! Below is the code from my app.js file: var app = angular.module("app", []); app.controller("AppCtrl", function($http) { var app = this; $http.get("./users/users.json") .success(function(data) { app.people = da ...

What happens when a function returns an undefined value after completing an operation?

When the getObject() function is called, it returns an undefined value. function getObject(a) { return { x : a } } console.log(getObject()); ...

Creating an effortless RSS feed using jQuery and Ajax

I could use some assistance with creating a basic rss feed that pulls content from websites like arstechnica. I've spent the last few hours researching how to do this, but I'm feeling a bit lost on the correct approach. Currently, I'm trying ...

Passing data from the Config Controller in AngularJS to another ControllerAre you looking to

I am facing an issue where I need to transfer data from the control (within config) to an external controller. I have attempted to use a factory to pass the data, but even after the data is modified, it still remains as 0 (I'm not sure what went wrong ...