Page 1 of 1

OpenTwebst & AHK

Posted: 08 Dec 2018, 11:43
by burque505
In my never-ending quest to find ways to use hammers as screwdrivers, I offer this OpenTwebst script.
Get OpenTwebst here. Documentation here.

There are many tutorials. Despite what some of the blurbs say, it works with IE 11. It has a macro recorder whose possibilities I have not yet fully explored.

I haven't seen any references on the web to others using AHK with OpenTwebst, thus this post.

For the code below, you must use the included file "trans2.xls" and you must edit the path to the file so the script can find it.
Also included is a tweaked, easy-to-view copy of IWB2Learner with zoom capability and some features restored, in case you find it useful. (I got most of the IWB2 Learner script here somewhere, but cannot find where anymore. All credit goes to the author, not me.)

EDIT: Commented out one unneeded line with a right-click action. It doesn't hurt, but adds nothing, so it's gone now. Still in archive code, though.

Excel.gif (286.97 KiB) Viewed 1538 times
Regards, burque505

Re: OpenTwebst & AHK

Posted: 09 Dec 2018, 22:40
by aeiklmr
My friend, I appreciate the link and the example of yours. This will allow me to finish more than 5 projects. I didn't had enough time to finish them, now I am trying with com and it's freaking useful.

Recommended. The fun fact I didn't go to bet today. I will go to the office in 2 hours without any sleep and this stuff gave me more so much relief.


Re: OpenTwebst & AHK

Posted: 10 Dec 2018, 09:09
by burque505
@aeiklmr, thanks for the kind words! I'm you're able to make use of it.

Re: OpenTwebst & AHK

Posted: 12 Dec 2018, 04:13
by adegard
@burque505 : Awesome! Thank you so much for this... :clap:
It's simplify the macro creation and script integration in AHK. It complete most of work I was trying to do with TagIE. :D

The only problem I have when I launch Twebst scripts: each time I need to confirm "Unknown Publisher" Warning of Windows... (I need to disable it for scheduling my scripts)

[edit] Questions: the Dom css used are id's and name, or there is a way to save full selector path (for dynamic pages) ?

Re: OpenTwebst & AHK

Posted: 13 Dec 2018, 10:33
by aeiklmr
Yeah it's awesome. Could anyone help me how to get the elements from a list?

I couldn't figure it out yet, I am struggling to solve this one:

Code: Select all

// Display all the links in a web page.
var coreObj = new ActiveXObject("OpenTwebst.Core");
var browser = coreObj.StartBrowser("");

var textToDisplay = "";
var anchorList    = browser.FindAllElements("a", "");
for (i = 0; i < anchorList.length; ++i)
	textToDisplay += anchorList(i).nativeElement.innerText + "\n";
Moderator Note: Added code tags. ~ sinkfaze

Re: OpenTwebst & AHK

Posted: 13 Dec 2018, 14:40
by burque505
I'm having trouble with it too, I'll post as soon as I figure something out (or if it stumps me). :D

Re: OpenTwebst & AHK

Posted: 13 Dec 2018, 14:42
by aeiklmr
Thank you sinkfaze!

I couldn't give up, here it is:

Code: Select all

core := ComObjCreate("OpenTwebst.Core")
browser := core.StartBrowser("")
anchors := browser.FindAllElements("a", "")
text    := ""

MsgBox % anchors.length
MsgBox % anchors.item(2).uiName
After this It will be easy to loop through the elements.

In the meantime at least I learned a lot and getting clearer with DOM, COM.

so much love for Ahk :wub:

I will replace the code I bypassed in my project. It's an EDI-like solution for delivery notes and invoices management. And the company could use it in other countries too. 4-6 /weeks/countries which were brainless manually work. RPA level 0. And it's a huge company.. Also realized the customers could benefit from it, since after the downloading I can send the e-invoice and other documents. I have a working COM+Outlook script which can be used in different situations.
I work as marketer so I am still a beginner, but I've automated a lot of task already.

Sorry but I am really proud now, I also did these calculations because without them most managers don't realize the importance of automation.

Back to ontopic what is the pro and con vs standard COM+IE ?

For me, it was just easier, didn't have enough time to deepen in COM+IE. But I'd like to know which one is better in different situations or COM+IE are more reliable and I should continue to learn it?

Re: OpenTwebst & AHK

Posted: 13 Dec 2018, 18:48
by burque505
@aeiklmr, nice job.
As I have time, I'm going to post some ports of Open Twebst's tutorials as I get them working. Here's IE macro - how to get programmatic control over HTML elements - Tutorial(3) (more or less :)) in AHK.

Code: Select all

;IE macro - how to get programmatic control over HTML elements - Tutorial(3)

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
    try ; leads to having the script re-launching itself as administrator
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"

core := ComObjCreate("OpenTwebst.Core")
browser := core.StartBrowser("")
sleep, 3000

browser.FindElement("input text",   "name = q").InputText("codecentrix")
browser.FindElement("input submit", "name = btnK").Click()

msgbox I will exit when you close this.

Regards, burque505
p.s. You probably know this already, but RPA giant UiPath has AutoHotkey "activities" that come with the program. It might be worth a try for you. The community edition is free.