TestProject Forum

Clear element contents Deletes Text Then Returns

Hi,

I’m new here so I wanted to ask a quick question. I’m currently writing a test for a login screen and I want to clear the content in the username textbox. I selected the action “Clear element contents (deletes any existing text”.

When I ran the test the content was cleared but the text returns in the username textbox after 2 seconds.

Is there a way which I can clear the contents completely which doesn’t allow the text to return?

1 Like

I am having the same issue…

Hello @adriandiez93.

You can try handling the textbox on your site/application in a few different ways.

  1. Click on the textbox:

image

Then use the ‘Send Keys’ action (note, this is not an element action), to send the BACK_SPACE key as many times as you need to delete the contents of the text box:

image

It’s important to run the ‘Send Keys’ action right after the click, so the text box will be in focus.

You can download an example test from here by following the link:

  1. Use JavaScript to clear the contents.
    Create a step of the action ‘Execute JavaScript’ and use any JavaScript code to reset the text box, for example:

image

This snippet will locate the text box based on it’s XPATH, and clear the text box.

document.evaluate( 'YOUR_XPATH' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.value = "";

You can get the test from here:

If you happen to be on mobile, you can use the ‘Execute Android Shell Command’ action after clicking/tapping on the text box to clear it’s contents with the following command:

adb shell input keyevent KEYCODE_DEL

And on iOS you can click on the text box to make the keyboard appear and record clicks/taps on the delete button.

1 Like