Hi guys!
Sorry for making you wait, I haven't set up email notification on updating of this thread and did not know you answered so fast. Thanks for this by the way.
I've tried Tom's script and it works fine with Firefox being not focused. Then I've tested my script thoroughly and can now conclude that the problem is not in the EVENT directive.
I've replaced the EVENT statement in my code with the javascript function to test the behaviour of the script. Here is a piece of my code configured for running on iMacros' test site. You can save it to text file with js extension and run from iMacros with Firefox focused and not.
Code: Select all
//imacros-js:showsteps no
function setCaretPosition(selector, caretPos) {
var el = window.document.querySelector(selector);
el.value = el.value;
// ^ this is used to not only get "focus", but
// to make sure we don't have it everything -selected-
// (it causes an issue in chrome, and having it doesn't hurt any other browser)
if (el !== null) {
if (el.createTextRange) {
var range = el.createTextRange();
range.move('character', caretPos);
range.select();
return true;
}
else {
// (el.selectionStart === 0 added for Firefox bug)
if (el.selectionStart || el.selectionStart === 0) {
el.focus();
el.setSelectionRange(caretPos, caretPos);
return true;
}
else { // fail city, fortunately this never happens (as far as I've tested) :)
el.focus();
return false;
}
}
}
}
function insertTextAtCursor(text) {
var sel, range, html;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode( window.document.createTextNode(text) );
}
} else if (window.document.selection && window.document.selection.createRange) {
window.document.selection.createRange().text = text;
}
}
iimPlayCode('URL GOTO=http://demo.imacros.net/Automate/TestForm1');
iimPlayCode('WAIT SECONDS=3');
setCaretPosition('#demo>fieldset>ol>li>textarea', 1);
iimPlayCode('WAIT SECONDS=3');
insertTextAtCursor('Aloha from Hawaii!');
When you switch focus from Firefox, the "Aloha..." text does not filled in. And I can't figure out why. Same happens when I use EVENT directive to text in chars into the input. By the way, on the site where my script is supposed to work the input field is made of editable div.