Jump to content

_FFFormSubmit not working


Recommended Posts

I'm trying to script commands to a command line for a text-based MUD that runs in a firefox window. I can get text to appear in the text box, but I can't get it to submit. It's weird because I'm able to get text to submit when I insert _FFFormSubmit in the _FFObj documented example.

I'm getting this error:

_FFFormSubmit ==> No match: No Elements found in form: getElementById('input')

Here is my code:

#include <FF.au3>

If _FFConnect(Default, Default, 10000) Then
$sInput = _FFObjGet("input", "id")
_FFObj($sInput, "value", "hello")
_FFFormSubmit("input", "id")
Else
MsgBox(64, "", "Can't connect to FireFox!")
EndIf

Here is my source code (The code for the text box is a few lines up from the bottom):

<?xml version="1.0"?>
<window id="main-window"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onMainLoad();" onunload="onunload();"
style="width:760px; height:480px;"
orient="vertical" persist="width height" windowtype="skotos:zealotry">
<script type="application/x-javascript" src="chrome://zealotry/content/browser-compat.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/my-world.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/init.js"/>

<script type="application/x-javascript" src="chrome://zealotry/content/jslib.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/filesystem.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/file.js"/>

<script type="application/x-javascript" src="chrome://zealotry/content/utils.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/md5.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/connection-xpcom.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/network.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/client.js"/>
<script type="application/x-javascript" src="chrome://zealotry/content/macro.js"/>

<script type="application/x-javascript" src="chrome://zealotry/content/zealotry.js"/>

<hbox style="-moz-box-flex: 1">
<iframe name="left-frame" id="left-frame" type="content"
     style="-moz-box-flex: 0; width: 145px; height: 100%; overflow: hidden"
     src="about:blank"/>

<keyset>
     <key id="dict-key" keycode="VK_F2" oncommand="helpMenuInit('dictionary');"/>
</keyset>
<vbox style="-moz-box-flex: 1">
     <toolbox>
<menubar id="sample-menubar">
     <menu id="file-menu" label="File" accesskey="F">
<menupopup id="file-popup" onpopupshowing="fileMenuInit();">
     <menuitem id="menuitem_logging" type="checkbox" accesskey="L"
label="Logging..." oncommand="onToggleLogging(event);"/>
     <menuitem id="menuitem_autolog" type="checkbox" accesskey="A"
label="AutoLog..." oncommand="onToggleAutoLog(event);"/>
     <menuseparator/>
     <menuitem label="Exit" oncommand="window.close();" keycode="VK_F4"/>
</menupopup>
     </menu>
     <menu id="edit-menu" label="Edit" accesskey="E">
<menupopup id="edit-popup" onpopupshowing="editMenuInit();">
     <menuitem id="menuitem_copy" label="Copy" oncommand="oncopy();" accesskey="C"/>
     <menuitem id="menuitem_paste" label="Paste" oncommand="onpaste();" accesskey="P"/>
     <!-- menuseparator/>
     <menuitem label="Load Macros" accesskey="O" oncommand="window.myMacros.processMacroCommand('LOAD');"/>
     <menuitem label="Save Macros" accesskey="A" oncommand="window.myMacros.processMacroCommand('STORE');"/>
     <menuseparator/>
     <menuitem label="Load Config" accesskey="L" oncommand="readConfigurationFile('menu');"/>
     <menuitem label="Save Config" accesskey="S" oncommand="writeConfigurationFile();"/ -->
</menupopup>
     </menu>
     <menu id="font-and-size" label="Options" accesskey="O">
<menupopup id="fonts-and-sizes-menu" onpopupshowing="optionMenuInit();">
     <menuitem label="Preferences" oncommand="doPrefs();"/>
</menupopup>
     </menu>
     <menu id="help" label="Help" accesskey="H">
<menupopup id="help-popup">
     <menuitem label="Help Contents" oncommand="helpMenuInit('content');" accesskey="H"/>
     <menuitem label="Changelog Notes" oncommand="helpMenuInit('changelog');" accesskey="C"/>
     <menuitem label="Whats New?" oncommand="helpMenuInit('new');" accesskey="N"/>
     <menuseparator/>
     <menuitem label="About Zealotry" oncommand="helpMenuInit('about');" accesskey="A"/>
</menupopup>
     </menu>
</menubar>
     </toolbox>
     <!-- iframe
name="scrollback"
id="scrollback"
type="content"
style="min-height: 70%; max-height: 70%"
src="about:blank"/>
     <splitter id="scroll_splitter" state="collapsed" collapse="before">
     <grippy/>
     </splitter -->
     <iframe name="center-frame" id="center-frame" type="content" flex="1" src="about:blank"/>
     <splitter state="open" collapse="before"/>
     <textbox spellcheck="true" autostretch="true" style="margin: 0; padding: 0" onkeypress="onInput();" rows="2" multiline="true" id="input"/>
</vbox>
<iframe name="right-frame" id="right-frame" type="content"
     style="-moz-box-flex: 0; width: 145px; height: 100%; overflow: hidden"
     src="about:blank"/>
</hbox>
</window>

Alternatively, if I can somehow use the _FFObj function to submit keys like {ENTER}, that would solve my problem, but I don't know how to do that either ... I see older versions of FF.au3 had a DispatchKeyEvent function that might help me, but it's no longer available. I opened FF and I noticed one hopeful thing:

_FFCmd('FFau3.simulateEvent=function simulateEvent(a,b,c){try{var d=document.createEvent(b);switch(b){case"MouseEvents":d.initMouseEvent(c,true,true,window,0,0,0,simulateEvent.arguments[4],simulateEvent.arguments[5],false,false,false,false,0,null);break;case"KeyboardEvent":d.initKeyEvent(c,true,true,null,false,false,false,false,simulateEvent.arguments[3],0);break;case"Event":d.initEvent(c,true,true);break}a.dispatchEvent(d);return 1}catch(e){return-3}return 0};')
It seems that _FFCmd can do key events. Anyone with more knowledge than me want to take a guess at how to setup the parameters to simulate an ENTER keystroke? Edited by johnnymo87
Link to comment
Share on other sites

Thanks for the tip, Dan!

It turns out I had these options (from the x-post):

_FFDispatchEvent(_FFObjGet("input", "id"), "keypress", 13)

ControlSend("[CLASS:MozillaWindowClass]", "", "", "{ENTER}")

For whatever reason _FFDispatchEvent didn't work for me ...

__FFSend: try{window.content.top.document.getElementById('input').value='hello world'}catch(e){'_FFCmd_Err';};
__FFRecv: hello world
__FFSend: try{FFau3.simulateEvent(window.content.top.document.getElementById('input'),'KeyboardEvent','keypress',13);}catch(e){'_FFCmd_Err';};
__FFRecv: 1

But ControlSend worked great. I'm facepalming so hard right now because I spent days trying to get more obscure tricks to work, and I completely overlooked ControlSend. Oh well!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...