Click a link if “class” exist on page? Imacros

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
User avatar
loverdo
Posts: 10
Joined: Mon Dec 05, 2016 10:05 pm

Re: Click a link if “class” exist on page? Imacros

Post by loverdo » Fri Jul 13, 2018 1:00 pm

Thank you very much for your help :D
im still having problem with your code :oops: All my attempts were unsuccessful :(

Ok the first part is working ... : SET !ERRORIGNORE YES

first.png
But the second part is :
second.png
When i turb ... : SET !ERRORIGNORE NO i get this :
third.png
third.png (5.56 KiB) Viewed 3020 times
IDK where is the problem :oops: I decided to contact my friend the programmer could possibly help me :mrgreen:
so he write me this code and modify like this :

Code: Select all

var x = document.body.innerHTML; var s,y,z; var n = x.split('available_dates = [');	y=n[1].split('];'); z=y[0]; 	var array = z.split(",");if (array.length>=2) 	{  		s=array[1];	} else if (array.length=1) {   	s=array[0];	}	alert (s);
If more than 1 Date available select the 2nd date

and If only one date available select it

this code is working and selecting the 2nd date :

Image


I modify the page and I just left 17-07-2018 in the page to make sure this line work and only one date available :

Image

After putting the code in imacros

Code: Select all

EVAL("var x = document.body.innerHTML;var y,z;var n = x.split('available_dates = [');y=n[1].split('];'); z=y[0]; var array = z.split(",");alert (array[0] );")
We are getting this :

Code: Select all

SyntaxError: can not parse macro line 11: EVAL("var x = document.body.innerHTML;var y,z;var n = x.split('available_dates = [');y=n[1].split('];'); z=y[0]; var array = z.split(",");alert (array[0] );")
This code also

Code: Select all

SET Avail_Dates EVAL("var x = document.body.innerHTML; var s,y,z; var n = x.split('available_dates = [');	y=n[1].split('];'); z=y[0]; 	var array = z.split(",");if (array.length>=2) 	{  		s=array[1];	} else if (array.length=1) {   	s=array[0];	}	alert (s);")
SyntaxError: wrong format of SET command at line 11

I told him that maybe the problem is that the color of the code has been changed in imacros but he did not believe me :mrgreen:
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Click a link if “class” exist on page? Imacros

Post by chivracq » Sat Jul 14, 2018 10:40 pm

loverdo wrote:Thank you very much for your help :D
im still having problem with your code :oops: All my attempts were unsuccessful :(

Ok the first part is working ... : SET !ERRORIGNORE YES
first.png
But the second part is :
second.png
When i turb ... : SET !ERRORIGNORE NO i get this :
third.png
IDK where is the problem :oops: I decided to contact my friend the programmer could possibly help me :mrgreen:
so he write me this code and modify like this :

Code: Select all

var x = document.body.innerHTML; var s,y,z; var n = x.split('available_dates = [');	y=n[1].split('];'); z=y[0]; 	var array = z.split(",");if (array.length>=2) 	{  		s=array[1];	} else if (array.length=1) {   	s=array[0];	}	alert (s);
If more than 1 Date available select the 2nd date

and If only one date available select it

this code is working and selecting the 2nd date :

Image


I modify the page and I just left 17-07-2018 in the page to make sure this line work and only one date available :

Image

After putting the code in imacros

Code: Select all

EVAL("var x = document.body.innerHTML;var y,z;var n = x.split('available_dates = [');y=n[1].split('];'); z=y[0]; var array = z.split(",");alert (array[0] );")
We are getting this :

Code: Select all

SyntaxError: can not parse macro line 11: EVAL("var x = document.body.innerHTML;var y,z;var n = x.split('available_dates = [');y=n[1].split('];'); z=y[0]; var array = z.split(",");alert (array[0] );")
This code also

Code: Select all

SET Avail_Dates EVAL("var x = document.body.innerHTML; var s,y,z; var n = x.split('available_dates = [');	y=n[1].split('];'); z=y[0]; 	var array = z.split(",");if (array.length>=2) 	{  		s=array[1];	} else if (array.length=1) {   	s=array[0];	}	alert (s);")
SyntaxError: wrong format of SET command at line 11

I told him that maybe the problem is that the color of the code has been changed in imacros but he did not believe me :mrgreen:
OK, I had seen your Reply yesterday afternoon, but I needed some "time" for a "good" Reply, ah-ah..., but I had to leave a bit later...

Yeah, but you've modified my "original" Script, I can see from the Prompts, you don't post the Script you are using, so I can't see/check what you've modified exactly, I can't test my Code directly on your Site/Page as you never posted the URL (or you could upload some (Full) HTML Saveas of the Page to your Thread, then I can test my Code on your Page), but my Code should work, I would think... I've already used (always for the Forum I think..., I don't think I use it for any of my own Scripts) several times extracting some '<script>' directly from the Source, and it works normally 8) , iMacros treats it like any other HTML Element that you can extract... But tja...!, I need to be able to test by myself if anything goes "wrong", maybe some "Special" Chars are contained in that JS Script that 'EVAL()' can't handle, I don't know...
I told him that maybe the problem is that the color of the code has been changed in imacros but he did not believe me :mrgreen:
Yep, your Friend is correct, never trust the Colours in iMacros (Editor), they are a bit "Buggy" anyway, ah-ah...!

But hum, what your Friend is doing with:

Code: Select all

var x = document.body.innerHTML; var s,y,z; var n = x.split('available_dates = [');	y=n[1].split('];'); z=y[0]; 	var array = z.split(",");if (array.length>=2) 	{  		s=array[1];	} else if (array.length=1) {   	s=array[0];	}	alert (s);
... is more or less just the same like me, except that he/she is extracting your JS Script at some higher HTML Level in the Page => 'BODY'... OK, why not..., not best-best Practice on FF in my Opinion, iMacros is always a bit "slow" I've noticed when extracting the 'BODY' or 'HTML' Content on a Page, especially for "large" Pages, "my" 'EXTRACT=HTM' on 'TYPE=SCRIPT' was extracting the same Data, and at the smallest HTML Level, is more efficient I would think...

But then, you cannot use that Syntax in 'EVAL()' (I think...!? :? ), I'm not completely sure, but I thought it only works in 'URL GOTO=javascript', not in 'EVAL()'... Hum, and for both, 'alert()' doesn't work anyway, has been broken since at least v8.40 for FF, first Version I tried to use some 'alert()' inn 'EVAL()' or 'URL GOTO=javascript', I've never managed to get it to work, even if it's "advertized" in the Wiki...! :oops:

And even if you used that Syntax in 'URL GOTO=javascript', pfff..., it's very cumbersome in my Opinion, you then need a "special" Technique which is more of a "Trick" actually to be able to pass some Data/Var from the 'URL GOTO' to the '.iim' Script... :oops:
It can be done, but hum..., pretty cumbersome like I said..., wouldn't be my first Choice to be honest, there are much simpler Ways...!
But anyway, if you REALLY want to go this Way, more Info about that "Method" if you have a look at the following Thread...:
- How to pass js variable to imacros variable

But the Script I had posted was pretty "straightforward", you can do everything you want from my 'Avail_Dates_Arr' Var, already demonstrated with 'Avail_Date_3'... :idea:
But you need to get 'Avail_Dates_Arr' populated, ah-ah...!, (empty in your Prompt, oops...!, NOT GOOD...! :shock: ), otherwise, nothing will work, ah-ah...!! :mrgreen:
Ask your Friend to review and to understand my Script, as I guess it might maybe be a little bit too "High Level" for you if you are not very-very Techie, ah-ah...! (no Offense of course...! :wink: ), then they should be able to help you further... But believe me, even if my Script looked a bit "complex", I usually always find the simplest Way to implement stg with iMacros... (in pure '.iim' at least...), hum..., even when TechSup says it's not possible, ah-ah...!. 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Click a link if “class” exist on page? Imacros

Post by chivracq » Tue Jul 23, 2019 10:54 pm

user wrote:
chivracq wrote:
Tue Jul 23, 2019 9:45 pm
user wrote: I found a way on how to automate the form that i was struggling to fill automatically. Nonetheless, thanks for your time anyway...
Ah...!?, OK, good News...! (And thanks for the Feedback/Follow-up, of course...)
But hum, the "proper" way to use a Tech Forum and to ask for Help is to also share your Script/Solution... 8) )
My solution is a different program that i found while browsing the net. but i respect the fact that i sought help here and i don't want to look like i'm promoting different products. Thus, i replied saying that my issue got fixed. i believe by the reply you gave me earlier, i think you realized that i'm new to scripting "from my"vague" Post and its "low Quality"..." isn't it ?
Ah..., alright..., well it's "OK" to mention on our Forum what other Tool(s)/Software you "considered" and ended up choosing to use..., especially as a "real User"... 8)
Don't worry, many "fake" Users register to the Forum regularly only to promote some other Tool, and they are way more "aggressive" than you, ah-ah...! So, the Opinion of "real" Users is always "interesting"..., sometimes iMacros "wins", and sometimes some other Tool "wins"... 8)

For all the Functionality that iMacros "covers" for 'Web-Automation', there are always at least 10 other Tools that can do "the same", about 'Web-Automation' / 'Web-Testing' / 'Data-Extraction' / 'Site-Scraping' / 'Downloading' / 'Uploading' / 'Performance-Testing' / 'Web-Monitoring' / 'Form-Filling' / 'Decision-Making' / 'Speed-Reaction' / etc... They all have their Pros and Cons, of course... ! :P
Most "competitive" Tools only cover 1-2-3 Areas I mentioned, while iMacros covers them all, even if iMacros is not always "the Best" in all Areas, its "Strength" comes from the Possibility to combine all those Areas and related Functionality in one same Script/Tool... 8)

So..., what other Tool did you go for, ah-ah...!?? :?:

EDIT:
"user" apparently didn't like my "Style" and requested to have their Account deleted, so I guess we'll never have "the" Answer about which Tool/Solution they chose... OK, fair enough... :|
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply