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
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 493 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: 8195
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)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...
Post Reply