Postal code value automatically disappears after moving to the next field

Hi,

I’m trying to input value into a postal code field but once after moving to next field the postal code value automatically disappers,

WebElement branchPostalCode = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/Create Branch/Page_Add Branch/input_Postal Code_ctl00ContentPlaceHolder1t_4fbdc5’), 30)
WebUI.executeJavaScript(‘arguments[0].value=“a1a-1a1”’, Arrays.asList(branchPostalCode))

The page may want to execute code when the value changes. When you set the value with JavaScript, you should ensure all relevant code is executed. Or, don’t use JavaScript.

Why are you not setting the value with WebUI.setText() ?

I tried WebUI.SetText(), but it is not entering the value at all in the field.

Is your test object using the id?

yes, it is using id.

What happens when you put this in the browser console:

document.querySelector("put-the-id-here").value = "post code here"

Sorry, the id must start with “#”

document.querySelector("#your-id").value = "post code here"

ids start with “#”
classes start with dot “.”
tag names can be used directly “div”

The error is saying, there is no tag with that name (which is absolutely correct :wink: )

Ok thanks :slight_smile:

So we proved your id works. What did the page do? Did it accept the value or did it disappear?

It accepted the value and didn’t disappear.

So, let’s change your JS code to this:

String js = 'document.querySelector("#your-id").value = "post code here"'
WebUI.executeJavaScript(js, null)

Make sure you don’t miss the different quote characters.

Let me know if it retains the post code in the field.

1 Like

It worked perfectly! Thank you!

1 Like