Robotics Javascript Help - Get Randomly Generated Text Box by Name and Hit Enter
I have a web adapter with a search box but there is no search button the only way to proceed is to hit enter. I found a previous thread which provided a solution for getting the text box element by ID however in this scenario the textbox ID is randomly generated each time the page loads.
The name of the textbox also always changes except the end of the name always ends with "_text".
I have tried to use "*_text" as my parameter int he following script but I keep getting an error. Any ideas what I am doing wrong or is there any better suggestions?
eventname = "keydown"
elementID = "*_text"
----------------------------------
function os_RaiseEvent(eventname,elementId)
{
var element = document.getElementsByName(elementId)[0];
var event;
if(document.createEvent)
{
event = document.createEvent("HTMLEvents");
event.initEvent(eventname, true, false);
if(eventname == "keydown" || eventname == "keyup")
{
event.keyCode = 13;
}
element.dispatchEvent(event);
}
else if(document.createEventObject)
{
event = document.createEventObject();
if(eventname == "keydown" || eventname == "keyup")
{
event.keyCode = 13;
}
element.fireEvent("on" + eventname, event);
}
return true;
}