Javascript for Imacros browser and image validation

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Javascript for Imacros browser and image validation

by apeiron on Thu Sep 14, 2017 4:10 pm

Hello,
I'm trying
iMacros Browser (x86) version 12.0.501.2305 trial
on windows 10 pro
and I also have the free version for Mozilla Firefox version 55.0.3 (x86 en-GB) which is what i used until now.

I need to use the image validation which seem to be working ok but I can't seem to be able to run the code in javascript through imacros browser. so my question is:
how do I run javascript code in Imacro browser? I cant see the .js files, if I open them directly in the editor i cant run them.
can I use IMAGESEARCH on firefox? everytime i try to run the code it fails to detect the image. (and if so do i need to install a different firefox plugin?) can I do so in another browser? tried chrome but it cant run .Js either.

alternatively, all i need to do is scan a small portion of the screen coming from a html/flash applet, its a very simple dynamic graph on a black background, but at certain times an event fires up with an colored arrow on it,
so I might be able to do the same thing just by looking for a pixel of a certain color, and then do something.
is there a way to detect if there's a certain color in an area of the screen with imacros/javascript without using imagesearch?
thanks a lot in advance!
apeiron
 
Posts: 4
Joined: Mon Sep 11, 2017 6:35 pm

Re: Javascript for Imacros browser and image validation

by chivracq on Fri Sep 15, 2017 9:49 am

apeiron wrote:Hello,
I'm trying
Code: Select all
iMacros Browser (x86) version 12.0.501.2305 trial
on windows 10 pro

and I also have
Code: Select all
the free version for Mozilla Firefox version 55.0.3 (x86 en-GB)
which is what i used until now.

I need to use the image validation which seem to be working ok but I can't seem to be able to run the code in javascript through imacros browser. so my question is:
how do I run javascript code in Imacro browser? I cant see the .js files, if I open them directly in the editor i cant run them.
can I use IMAGESEARCH on firefox? everytime i try to run the code it fails to detect the image. (and if so do i need to install a different firefox plugin?) can I do so in another browser? tried chrome but it cant run .Js either.

alternatively, all i need to do is scan a small portion of the screen coming from a html/flash applet, its a very simple dynamic graph on a black background, but at certain times an event fires up with an colored arrow on it,
so I might be able to do the same thing just by looking for a pixel of a certain color, and then do something.
is there a way to detect if there's a certain color in an area of the screen with imacros/javascript without using imagesearch?
thanks a lot in advance!

Your Version of iMacros for FF is missing..., probably v9.0.3 or v8.9.7...?

You can only run "natively" '.js' Scripts from FF with the iMacros for FF Add-on.
Or I think it's possible as well to run them from some "3rd Party" Compiler using the iMacros Scripting Interface but I think it's a bit cumbersome...

I've never used 'IMAGESEARCH', I think...?, I'm not sure anymore, ah-ah...!, I might have tried it or tried to use it once several years ago for some Thread on the Forum, but I (mostly) only use the iMacros for FF Free Add-on (currently v8.8.2 (+ Pale Moon v26.3.3 (=FF47)) for my "Prod" Env., and v8.9.7 (+ FF v55.0.3), as well for the Forum, both on Win10-x64), and occasionally for IE or CR for Cases on the Forum really specific to only one Browser/Version but I've never used iMB (the iMacros Browser), and according to the Wiki for 'IMAGESEARCH', this Command only works on FF in combination with iMB being installed on the same Machine (as it requires some external C++ Runtime Files)... But it is mentioned that Flash Objects are not supported on FF, so I'm afraid this won't be an option for you...

But hum..., interesting Scenario actually, ah-ah...! :D

Some "Workaround" I could think of, but OK, follow me, it's a bit cumbersome, ah-ah...!, would be to first download a mini-Screenshot of your Flash Object using 'CONTENT=EVENT:SAVE_ELEMENT_SCREENSHOT', Example:
Code: Select all
TAG POS=1 TYPE=EMBED ATTR=ID:menuinterf CONTENT=EVENT:SAVE_ELEMENT_SCREENSHOT
... then to use/misuse Google Images 'Search by Image' by first uploading your Image once to some Web-Site of yours or some Forum like in this current Thread, and wait until Google has indexed your Image to then use it for Image Comparison from the Google Site itself.

In your Script itself, make sure to use 'FILEDELETE' to first delete any previous Version of the '.png' File downloaded by 'SAVE_ELEMENT_SCREENSHOT' as it doesn't seem to replace a previous Version, or to give your '.png' File a unique Name.

Oh...!, but I was going to tell you to make sure to download the '.png' File in the Default iMacros 'Downloads' Folder (=> don't use 'ONDOWNLOAD' to specify a different Location) because from v9.0.3 for FF, 'FILEDELETE' only works now on that Default Folder, but-but-but, ah-ah-ah...!, the File Upload Functionality that you will need to upload your '.png' to Google Images is not supported anymore in v9.0.3, oops...! OK, that means that you are obliged anyway to revert to v8.9.7 (which still works on FF v55.0.3).

And some other Workaround is simply to (re-)convert your "original" '.js' Script to an '.iim' Script, ah-ah...! :twisted:
=> Then you would be able to use 'IMAGESEARCH' on iMB or IE...
I don't use any '.js' Scripts myself, I do all my "Coding" in pure '.iim' and my '.iim' Scripts certainly do more "complex" Things with "extreme" Conditional Behaviour than what I have ever seen from other Users posting their Scripts in '.js' on the Forum and I've never seen "anything" done in '.js' that I wouldn't find a way to do in pure '.iim'...

If you go for "my" Workaround using 'Google Images', post your final Script, that could be interesting for other Users, I think it is the first Thread we have with this Scenario, and I might be able to improve/tune it a bit, ah-ah...!
I would be interested as well once you've uploaded your "Control" Image especially if you don't upload it to this current Thread on our Forum as I will notice it by myself otherwise of course, if you could post the URL (if it's not too "secret" ah-ah...!) and/or measure the Time that Google will need to index it... But OK, I might run the Test myself on our Forum (which gets pretty quickly indexed), ah-ah...!
=> Mini-Test on a Keyword already, ah-ah...!: qmyqoqu
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript for Imacros browser and image validation

by apeiron on Fri Sep 15, 2017 11:36 am

Hi chivracq!

thank you so much for getting back to me, a lot of really useful info! I have the latest version for FF.

good shout about renaming the js to iim and carry on with imacro browser I didnt know that was an option :D Ill try that and and see how far I can get, but yeah mainly I'm using the js for conditional statements and loops, not sure what you mean with extreme conditional behaviour? that sounds like could be useful
in the meantime i downloaded visual studio in case things needs to get more serious.

using google isn't an option unfortunately as the graph changes every minute or so and I need to be able to react to the event firing within seconds or less ideally.
I'm reading around and another option could be to use js function getImageData() and scan the returning array for that pixel color change I mentioned. I wonder if this is possible from within imacro/js environment.
but seems worth a try unless i find better options!
apeiron
 
Posts: 4
Joined: Mon Sep 11, 2017 6:35 pm

Re: Javascript for Imacros browser and image validation

by chivracq on Fri Sep 15, 2017 3:23 pm

apeiron wrote:Hi chivracq!

thank you so much for getting back to me, a lot of really useful info!
Code: Select all
I have the latest version for FF.


good shout about renaming the js to iim and carry on with imacro browser I didnt know that was an option :D Ill try that and and see how far I can get, but yeah mainly I'm using the js for conditional statements and loops, not sure what you mean with extreme conditional behaviour? that sounds like could be useful
in the meantime i downloaded visual studio in case things needs to get more serious.

using google isn't an option unfortunately as the graph changes every minute or so and I need to be able to react to the event firing within seconds or less ideally.
I'm reading around and another option could be to use js function getImageData() and scan the returning array for that pixel color change I mentioned. I wonder if this is possible from within imacro/js environment.
but seems worth a try unless i find better options!

About '.js' vs '.iim', it's not simply only about "renaming the js to iim", but about "converting" the '.js' Script (back) to '.iim'...

Hum, OK for Loops, that can be a "Legit" Use for a '.js', even if Loops and Nested Loops can be done in pure '.iim' (many Threads about that on the Forum), "my" '.iim' Scripts can decide by themselves if and how many times they have to loop, even for nested Loops, if some parts of the Script need to be skipped, they can adapt to a Site if the HTML Structure changes, or even modify themselves or other Scripts, on-the-fly or permanently, and they can "communicate" with each other... And of course with some heavy Logging and they "alert" me if anything "goes wrong"... But OK, I use a few Tricks and Techniques, some relying on some undocumented and unsupported "Features" and even sometimes rely on Bugs that for a few I maybe don't want to "advertize" too much in case they get "solved", oops...!
If you post your Script I can have a look and tell you if your Script can "easily" be converted to an '.iim' Script...

But OK, hum, about 'getImageData()', I'm not completely convinced it will "work" as this 'getImageData()' seems to have a lot of (Security) Restrictions and is meant to be used from a Web-Page hosted on some Web-Server to manipulate Images located on the same Domain. I'm not sure this Command will do anything if run from iMacros...

And I understood that your Image is embedded/encapsulated into some Flash Object, which adds an extra Layer to access the Image and its related Data...

But very often, Values are passed to the Flash Object from the HTML Page and if they are already visible from the Source Code outside the '.SWF' Object (and don't change dynamically within the '.SWF' Object only), then you can access/extract (and isolate) them with some 'TAG' + 'EXTRACT=HTM' on the '.SWF' Object (+ 'EVAL()'). I use this Technique indeed myself in one of my Scripts:
Code: Select all
TAG POS=1 TYPE=EMBED ATTR=ID:menuinterf EXTRACT=HTM
SET Pseudo EVAL("var s='{{!EXTRACT}}'; var y,z; y=s.split('pseudo='); z=y[1].split('&'); z[0];")

The 'menuinterf' Object is a Flash Object on that Site and the 'EXTRACT=HTM' contains about 50 different Values/Properties from which I isolate the Value for the 'Pseudo' Property passed to the Flash Object:
Code: Select all
<embed type="application/x-shockwave-flash" src="/navig/main_menu.swf" style="outline: 1px solid blue;" id="menuinterf" name="menuinterf" bgcolor="#FFCCCC" quality="high" menu="false" wmode="opaque" allowscriptaccess="sameDomain" flashvars="... many Vars here...!&amp;pseudo=MyPseudo&amp;... and many other Vars here...!" width="820" height="250">


If you post your Script and/or URL of the Site (if it doesn't require Login&Password), I can have a look and see if I can find some "Creative" Solution, ah-ah...! :oops: :P
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript for Imacros browser and image validation

by apeiron on Sat Sep 16, 2017 9:51 am

ah makes sense, tricky indeed, the website object doesn't seem to expose anything to me hence my attempt at detecting the image instead.

you can have a look at https://www.tradingview.com/chart/mP0cqb0b/# if it shows those little blue and pink arrows, that's what I'm after. otherwise its essentially just like another bar in the graph.
there's a data window that exposes some values but not the ones I need.
apeiron
 
Posts: 4
Joined: Mon Sep 11, 2017 6:35 pm

Re: Javascript for Imacros browser and image validation

by chivracq on Sat Sep 16, 2017 7:31 pm

apeiron wrote:ah makes sense, tricky indeed, the website object doesn't seem to expose anything to me hence my attempt at detecting the image instead.

you can have a look at https://www.tradingview.com/chart/mP0cqb0b/# if it shows those little blue and pink arrows, that's what I'm after. otherwise its essentially just like another bar in the graph.
there's a data window that exposes some values but not the ones I need.

OK, just back from some funny Evening, I tried to have a look but pfff, not conclusive, I can't load any Page on this Site, doesn't matter what I try on the URL... (And not sure if it comes from my Connection or from the Site... Hum, if I can't post, then it came from my Co, ah-ah....!)

EDIT: Hum Posting went directly OK, was a good first mini-Test, but checking the Site still doesn't work for me, the "Site" tried to load some 's.new-trading.com' Site instead of your ULR, and it never works, sorry dunno... :?
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript for Imacros browser and image validation

by apeiron on Sun Sep 17, 2017 2:36 am

hm yes probably it was a weird link to my customized chart that couldn't be accessed if not logged in, try this
https://uk.tradingview.com/chart/?symbol=FX:GBPUSD

or if that doesnt work either, you could just go to tradingview.com, search for say a currency pair in the searchbox, say "gbpusd" then click on "interactive chart" in the top right (not sure if you might have to be logged in to see that but its free) and you should be able to get the idea once any chart shows..seems to be just a flash? object type that doesn't seem to expose anything whatsoever
apeiron
 
Posts: 4
Joined: Mon Sep 11, 2017 6:35 pm

Re: Javascript for Imacros browser and image validation

by chivracq on Mon Sep 18, 2017 9:36 am

apeiron wrote:hm yes probably it was a weird link to my customized chart that couldn't be accessed if not logged in, try this
https://uk.tradingview.com/chart/?symbol=FX:GBPUSD

or if that doesnt work either, you could just go to tradingview.com, search for say a currency pair in the searchbox, say "gbpusd" then click on "interactive chart" in the top right (not sure if you might have to be logged in to see that but its free) and you should be able to get the idea once any chart shows..seems to be just a flash? object type that doesn't seem to expose anything whatsoever

OK, was a bit busy during the WE, ah-ah...!, finally managed to load your original URL after 20-30 Tries, very heavy Site built with some "interesting" Technologies by some talented Programmer I would think, even if I'm always directly a bit "suspicious" when I notice a Typo directly on the first Line of the Source ("fina[n]cial", grrr...!), ah-ah...! And the Site seems to be causing some steady Memory Leak and CPU Consumption (on Pale Moon v26.3.3, which is actually optimized against Memory Leaks, so I guess it must be even worse on plain FF, ah-ah...!)

But OK, I was able to have a look at both URL's, well good news is there is no Flash at all on those Pages, so all the Data you are after must be in the Source, but I don't know what exactly you want to "watch" or extract...?

If it's one of those Red or Green mini-Boxes, especially if/when they switch from Red to Green or the other way around, they can easily be tagged (and extracted) and their RGB Value is included in the 'EXTRACT', you don't need any 'IMAGESEARCH' or any "cumbersome" way, the "Job" is then pretty straightforward for iMacros (all Browsers/Versions) and there isn't hardly any Difficulty... Look for example at the Data contained in the 'EXTRACT''s...:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
'URL GOTO=https://www.tradingview.com/chart/mP0cqb0b/#
TAG POS=1 TYPE=SPAN ATTR=TXT:Bitcoin<SP>/<SP>British<SP>Pound,<SP>5,<SP>COINFLOOR,<SP>Hei* EXTRACT=HTM
TAG POS=1 TYPE=SPAN ATTR=TXT:L2990.00 EXTRACT=HTM
TAG POS=1 TYPE=SPAN ATTR=TXT:My<SP>Strategy<SP>(15,<SP>7,<SP>1,<SP>9,<SP>1,<SP>2,<SP>4,* EXTRACT=HTM

=> Data extracted:
Code: Select all
<span style="font-weight: normal; font-size: 17px; color: rgb(217, 217, 217); border-color: rgb(217, 217, 217); outline: 1px solid blue;" class="pane-legend-line apply-overflow-tooltip no-context-menu main">Bitcoin / British Pound, 5, COINFLOOR, Heikin Ashi</span>
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10-x64.)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript for Imacros browser and image validation

by chivracq on Sat Sep 23, 2017 3:07 pm

Okay..., no Follow-up anymore, 5 days later, I guess you probably got your Script to work and we won't hear from you anymore..., until you get a new Pb/Qt, for which I then won't try to help you again as I only help Users using the Forum "a bit correctly", which implies a neat Follow-up and sharing their Solution... :idea:
Hum, and not deleting their Thread(s) once they got their Solution, ah-ah...! Pity, I was following that Thread on SOF... :roll:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6490
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 8 guests

-->