0

I'm trying to automate some boring, duplicated data entry into a web application at work. I'm sorry if the answer is well known but I've spent hours in google trying to figure it out. The problem is, in the web-based application none of the links are simple HTML, 'a href' type links, they use javascript.

I can see in one of the .js files for the website that the function invoked when a link is clicked is defined as follows

function sendEvent(eventtype, targetid, value)

...and with the Firefox debugger I can see that in order to do the simple page navigation I want to do, my extension has to invoke the websites js function as follows (the 'value' parm can be null)

 sendEvent("click", "mx709")

I found this similar question. The suggested method is

content.wrappedJSObject.funcFromPage()

or

getBrowser().contentWindow.wrappedJSObject.funcFromPage();

... but running either of those lines in my extension doesn't seem to invoke the function and hence "click" the link I want clicked

EDIT 1 - in case it wasn't clear, the code I actually put into my extension was:

content.wrappedJSObject.sendEvent("click", "mx709[R:3]");

EDIT 2 - Also tried this, no dice. I have the Firefox debugger open, and a breakpoint on the top of the 'sendEvent()' function. Every time I click a link in this web app, I hit the breakpoint, when I try lines like the above (or the following), the breakpoint is not tripped

window.content.document.defaultView.wrappedJSObject.sendEvent("click", "mx709[R:3]");
Community
  • 1
  • 1

1 Answers1

0

The wrappedJSObject method should work.

Open up scratchpad and copy paste this:

var indexOfTabWithMyDocument = 1; //1 means 2nd tab, 0 is first tab
Services.wm.getMostRecentWindow('navigator:browser').gBrowser.tabContainer.childNodes[indexOfTabWithMyDocument].contentWindow.wrappedJSObejct.FUNCTIONTORUN()

Set the environment of scratchpad to browser. And run. It will work.

Noitidart
  • 35,443
  • 37
  • 154
  • 323