OpenTwebst & AHK

Post your working scripts, libraries and tools
burque505
Posts: 1003
Joined: 22 Jan 2017, 19:37

OpenTwebst & AHK

08 Dec 2018, 11:43

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.

Spoiler
Excel.gif
Excel.gif (286.97 KiB) Viewed 1064 times
Regards, burque505
Attachments
Twebst.zip
(16.17 KiB) Downloaded 38 times
User avatar
aeiklmr
Posts: 10
Joined: 09 Dec 2018, 22:28
Location: Hungary
Contact:

Re: OpenTwebst & AHK

09 Dec 2018, 22:40

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.

Thanks!
I like to think extroverts have attention dependency disorder.
burque505
Posts: 1003
Joined: 22 Jan 2017, 19:37

Re: OpenTwebst & AHK

10 Dec 2018, 09:09

@aeiklmr, thanks for the kind words! I'm you're able to make use of it.
Regards,
burque505
User avatar
adegard
Posts: 77
Joined: 24 Nov 2017, 05:58
GitHub: adegard

Re: OpenTwebst & AHK

12 Dec 2018, 04:13

@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) ?
User avatar
aeiklmr
Posts: 10
Joined: 09 Dec 2018, 22:28
Location: Hungary
Contact:

Re: OpenTwebst & AHK

13 Dec 2018, 10:33

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("http://www.codecentrix.com/");

var textToDisplay = "";
var anchorList    = browser.FindAllElements("a", "");
for (i = 0; i < anchorList.length; ++i)
{
	textToDisplay += anchorList(i).nativeElement.innerText + "\n";
}
WScript.Echo(textToDisplay);
Moderator Note: Added code tags. ~ sinkfaze
I like to think extroverts have attention dependency disorder.
burque505
Posts: 1003
Joined: 22 Jan 2017, 19:37

Re: OpenTwebst & AHK

13 Dec 2018, 14:40

I'm having trouble with it too, I'll post as soon as I figure something out (or if it stumps me). :D
User avatar
aeiklmr
Posts: 10
Joined: 09 Dec 2018, 22:28
Location: Hungary
Contact:

Re: OpenTwebst & AHK

13 Dec 2018, 14:42

Thank you sinkfaze!

I couldn't give up, here it is:

Code: Select all

core := ComObjCreate("OpenTwebst.Core")
browser := core.StartBrowser("http://www.codecentrix.com/")
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?
I like to think extroverts have attention dependency disorder.
burque505
Posts: 1003
Joined: 22 Jan 2017, 19:37

Re: OpenTwebst & AHK

13 Dec 2018, 18:48

@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
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}


core := ComObjCreate("OpenTwebst.Core")
browser := core.StartBrowser("http://www.google.com/")
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.

browser.Close()
core.Reset()
ExitApp
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.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Frosti and 40 guests