0

I am writing an AutoHotkey script to enter data into an Oracle PeopleSoft application. Rather than trying to locate specific elements on the page, I want to try execute JavaScript commands directly instead.

So instead of using a hardcoded MouseClick, left, 205, 281 to click the "Add New Values" button, I want to directly run submitAction_win0(document.win0,'#ICSwitchMode')

I've tried entering commands directly into the address bar, but this doesn't seem to have any effect.

#k::
   jsCommand = javascript:submitAction_win0(document.win0,'#ICSwitchMode');
   Send, !d                  ; places cursor in URL field
   Send, %jsCommand%{Enter}  ; submit JS command (doesn't work)
Return

According to this AHK thread, it should be possible to accomplish this using a ScriptControl object, but I'm a bit unsure how to use them.

How can I execute JavaScript commands using AutoHotkey?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
  • You'll only be able to call methods that are globally available that way. – Kevin B Aug 23 '17 at 18:17
  • What shows up in the JS console? – Derek 朕會功夫 Aug 23 '17 at 18:18
  • @Derek朕會功夫 `SCRIPT5007: The value of the property 'submitAction_win0' is null or undefined, not a Function object` ZZ_KRONOS.ZZ_KRONELIG_DPT.GBL, line 1 character 1 – Stevoisiak Aug 23 '17 at 18:22
  • 2
    There you go, `submitAction_win0` is not defined and therefore you can't call it. – Derek 朕會功夫 Aug 23 '17 at 18:23
  • @Derek朕會功夫 I'm confused why it would work when pressing the button directly, but not when entered in the URL bar. The button element is defined as `Add a New Value` – Stevoisiak Aug 23 '17 at 18:34
  • There are many reasons why it won't work. Are you actually entering the JavaScript code into the correct page? Did you wait for the page to finish loading before executing it via the address bar? Was `submitAction_win0` dynamically generated? – Derek 朕會功夫 Aug 23 '17 at 18:36
  • 1
    It's easy to automate internet explorer with Autohotkey see the following link for a good tutorial: https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/ – Oleg Aug 28 '17 at 07:50
  • @Oleg Can you post that comment to [Find and fill an input field with AutoHotKey](https://stackoverflow.com/q/30102439/3357935)? – Stevoisiak Aug 28 '17 at 13:29
  • @StevenVascellaro I can but don't know if I should... please do it yourself if you think mentioning that tutorial there will be helpful. – Oleg Aug 28 '17 at 18:52

1 Answers1

0

Per an example I used in a previous question's answer for controlling IE, walking the DOM, etc:

F3::
wb := ComObjCreate("InternetExplorer.Application") ; Create a IE instance
wb.Visible := True
wb.Navigate("http://google.com")
Sleep, 5000
SendInput, This is test.{Enter}
Sleep, 5000
wb.document.getElementById("lst-ib").value := "This is another test."
wb.document.getElementById("_fZl").click()
return
David Metcalfe
  • 2,237
  • 1
  • 31
  • 44