Question

3
Replies
1583
Views
MarkP977 Member since 2017 16 posts
Nationwide
Posted: 2 years ago
Last activity: 2 years 4 months ago
Closed

Robotics - Using Javascript - send Enter key to text box

I am creating an automation in a web database with a search box that does not have a search button. The only way to trigger the search function is to hit enter in the text box. I am using the following javascript which compiles but does not achieve the enter press. Any ideas or suggestions would be greatly appreciated:

function os_RaiseEvent(eventname)
{
var element = document.querySelector('[id$="_text"]');
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;
}

Data Integration Java and Activities Robotic Process Automation
Moderation Team has archived post
Share this page LinkedIn