What I was suggesting is logging the value of input. It is probably undefined or null. (And hence it is not an HTML input object and so does not have the select method.)
You’re running this code on the page loaded event, aren’t you…
Yeah you can’t do this until the input actually exists. Use the Expression element from toolbox (script empty by default) and then change its script once the input in question becomes visible via the conditions tab.
If you share your editor, a Good Samaritan may help here. At the moment, I’m away from keyboard and so am just providing general advice.
Your issue is that you are attempting to find (via getelementbyid) an element that does not yet exist in the page. And so your script fails. If you trigger it on “the input in question is visible” it will work, most likely.
… but if you did want to execute some script on page load that waits for an input and then, whenever it first shows up on the page, set focus to it and select its contents, you could run the following script in a Run JavaScript action.
What this does is uses a mutation observer to watch for the element specified with selector (which should be a CSS selector - in this case an ID selector which is a string like '#element-id', so in your case you called your element ‘cus-input’, so the selector for it would be '#cus-input'). In my example code below, my element is called ‘#hidden-input’ (so you’d replace that with your input’s ID.
The first part of the code defines the function waitForElement and then in the last line, we call that function. It waits until the specified element appears in the page and executes the code in the .then() clause (which here just calls the element’s .focus() and .select() methods.
Here’s the code - you’d trigger this on the Page Loaded event:
function waitForElement(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector))
observer.disconnect();
}
})
observer.observe(document.body, {
childList: true,
subtree: true
})
})
}
waitForElement('#hidden-input').then((elm) => (elm.focus(), elm.select()))