InvalidElementStateException: invalid element state Error while using setText

Hello,
I am getting an exception “InvalidElementStateException: invalid element state” while setting text to one table populated on webpage, It is able to click on object “Registration1” however not setting text, similarly for next “100.00%”.
I have tried the solutions available on katalon community like enhancedClick, delay and some webElement script as well. Not working.
Can someone look?


1 Like

What type of HTML element the object “Registration1” is selecting? Please show the locator it has.

I guess, “Registration1” is selecting a <td> element.

WebUI.setText() will not work against a <td> element.

WebUI.setText() will only work against a <input> element.

It is a mistake to apply WebUI.setText() against a <td> element. Do you understand this?

Yes, it is …
I have used sendkeys as well but that also did not work…
Any other way to input text on ?

Are you saying, you want to change the text content of a <td> element by you test script?

Yes i have to clear the “Registration 1” text and replace it with my input text.
Registration 1 is just a placeholder for text box.

Let me ask you again, is the “Registration 1” is pointing a <td> element?
Would you show us the locator of the TestObject?

Let me assume that you manually opened a browser and navigate to the page.

Then, can you manually (without test script) somehow change the text of the HTML element which your “Registration 1” points to? — I guess, you cann’t. But let me ask you if you can do it.

Are you expecting that a Katalon test script should be able to change the text content of a <td> element in a HTML page?

Locator of text object:

I want to add text in that table via my katalon test script.
I saw answer in another similar question page in cummunity to use robot class

WebUI.delay(1)
Robot robot = new Robot()
robot.keyPress(KeyEvent.VK_A)

I can see it appended ‘a’ in the table like ‘Registration1a’
I think i can use this but let me check how to provide combination of keyboard inputs

I have used below code and it can enter ‘test’ in the table however it is so lengthy to write.

WebUI.delay(1)
Robot robot = new Robot()

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_DELETE);
robot.keyRelease(KeyEvent.VK_DELETE);

robot.keyPress(KeyEvent.VK_T)
robot.keyRelease(KeyEvent.VK_T)
robot.keyPress(KeyEvent.VK_E)
robot.keyRelease(KeyEvent.VK_E)
robot.keyPress(KeyEvent.VK_S)
robot.keyRelease(KeyEvent.VK_S)
robot.keyPress(KeyEvent.VK_T)
robot.keyRelease(KeyEvent.VK_T)

Could you show us the HTML souce of the page?

I don’t need the full source. I just want to have a look at the section of <tr><td>...</td>...</tr>.

I want to check if the <td> contains a <input type="text"> element or not.

It is NOT POSSIBLE. Please read what @kazurayam is telling you. It does not matter how many different ways you try to do it, it will NOT work. Worse than that, the page wasn’t designed to work that way.

Question: How does a real human user enter text in that <td> element? Can you do it by hand?

1 Like

Hi Russ, I can able to edit it manually .

May be I misunderstood your question, I can able to edit the text box manually in web page I meant

This is the code:

I don’t know what to tell you. <td> elements cannot be modified by regular human users. Therefore, your test code should not, either.

I sincerely hope you’re not confusing a developer’s ability to modify the HTML and a regular user’s ability to enter a value.

1 Like

Screenshot 2023-12-08 at 7.43.30

You screenshot shows that a table cell gets focused and highlighted with a border in blue color.

A bare-born <TD> element will NEVER get highlighted when it is clicked.

So I presume that your web page has some JavaScript-based UI extension library. It accepts a click event to a <td> element and perform some trick. The <td> seems to change its style to be bordered blue; it seems to let you do some keybord input into the <td> element.

@shruti1

Are you aware what sort to UI extension library the page has injected? angular, react, vue, ember, … If you do not know it, ask the developers.

Once you got to know it, you can read the documentation of the libray and study it.

Then you would be able to get better idea how to interact with it.


I guess,

  1. you want to send a click to your target <td>.
  2. once you click the <td> element, the JavaScritp library creates a new <input type="text"> with just the same width-height, and locate the <input> element over the <td> element.
  3. For a human, it looks as if a cell of the table turned to be manipulatable. But you should know, it is a trick. A new <input> element is generated and overlayed. The real <td> element is hidden underneath.
  4. The newly placed <input> element will accept character input from keyboad. When you move the focus out of the <input> element, the JavaScript will aquire the text and transfer it into the <td> underneath; then remove the <input> element. You will find the <td> element to have the new characters you just haved typed in.

A trick completed!

This is just what I guess. I have ever seen several JavaScript libraries that work this way.

@shruti1

You should study the web page as target, should understand how it work internally. It’s complexed. It is always difficult to test such JavaScript-driven HTMLs using any UI-automation tools. Without thorough understanding about your target HTML, you won’t be able to test it with the Selenium-based testing tools like Katalon Studio.

Don’t rely on the Spy and Record tools of Katalon Studio. These tools are dum. They would not help you to work with HTMLs with JavaScript extention libraries.

1 Like

Is the target web page public to the Internet? Can other guys in this forum get access to the URL? If yes, tell it to us.

Without having the target URL accessible for us, it would be very difficult for the guys in the forum to make any productive comments about your case.

Thanks @kazurayam for your detailed answer and helping me.
I will ask developers and study it. Looks like you got it correct JavaScript-driven HTML.

The target webpage is not public, it specific to the clients only. Even employee cannot access without the permissions. Sorry for that.

Is it OK to close this topic?