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

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

Post by loverdo » Wed Jul 04, 2018 1:37 pm

I have a website that constantly changes the page content

If class='disp' not available (Website Source): I want to repeat the imacros loop

Code: Select all

class='overable'>2018-07-05 <a class='full' type='button'>10<i>:30</i></a> 
class='overable'>2018-07-06 <a class='full' type='button'>10<i>:30</i></a> 
class='overable'>2018-07-07 <a class='full' type='button'>10<i>:30</i></a>
class='overable'>2018-07-08 <a class='full' type='button'>10<i>:30</i></a> 
But if class='disp' available I want imacros to choise This date "2018-07-07" and click on the link https://google.com in at this date then continues running imacros next line

Code: Select all

class='overable'>2018-07-05 <a class='full' type='button'>10<i>:30</i></a>
class='overable'>2018-07-06 <a class='dispo' type='button' href='javascript:void(0)' onclick='ajaxCall("ajax_form_status", "google.com")'>10<i>:30</i></a>
class='overable'>2018-07-07 <a class='dispo' type='button' href='javascript:void(0)' onclick='ajaxCall("ajax_form_status", "google.com")'>10<i>:30</i></a>
class='overable'>2018-07-08 <a class='full' type='button'>10<i>:30</i></a> 

Thank you very much i love you imacros :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 » Wed Jul 04, 2018 2:59 pm

loverdo wrote:I have a website that constantly changes the page content

If class='disp' not available (Website Source): I want to repeat the imacros loop

Code: Select all

class='overable'>2018-07-05 <a class='full' type='button'>10<i>:30</i></a> 
class='overable'>2018-07-06 <a class='full' type='button'>10<i>:30</i></a> 
class='overable'>2018-07-07 <a class='full' type='button'>10<i>:30</i></a>
class='overable'>2018-07-08 <a class='full' type='button'>10<i>:30</i></a> 
But if class='disp' available I want imacros to choise This date "2018-07-07" and click on the link https://google.com in at this date then continues running imacros next line

Code: Select all

class='overable'>2018-07-05 <a class='full' type='button'>10<i>:30</i></a>
class='overable'>2018-07-06 <a class='dispo' type='button' href='javascript:void(0)' onclick='ajaxCall("ajax_form_status", "google.com")'>10<i>:30</i></a>
class='overable'>2018-07-07 <a class='dispo' type='button' href='javascript:void(0)' onclick='ajaxCall("ajax_form_status", "google.com")'>10<i>:30</i></a>
class='overable'>2018-07-08 <a class='full' type='button'>10<i>:30</i></a> 
Thank you very much i love you imacros :mrgreen:
Yeah, well, CIM...! (Again...!) :mrgreen: (Read my Sig...)

And hum..., your previous Thread where I + some other Advanced User tried to help you has been "waiting" for some Follow-up from your Side for 1.5 years already, oops...! :shock:
Then I guess I will pass on this one, tja...! :wink:
(But you can still follow up on your previous Thread and finish it a bit correctly with a Solution..., ... and I guess you can still bump this current one in 1.5 years if you still need a Solution then... :idea: )

>>>

+ Parallel Thread on SOF:
- Click a link if “class” exist on page? Imacros
(No Replies yet...)
- (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...
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 » Wed Jul 04, 2018 3:27 pm

you got me :mrgreen:
i feel very bad right now :oops:
but last time your really helped me and i forgot to say thank you !!!
Im so sorry but old problem is over :cry:
can you please please help me on this one :cry:
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 » Wed Jul 04, 2018 3:35 pm

loverdo wrote:you got me :mrgreen:
i feel very bad right now :oops:
but last time your really helped me and i forgot to say thank you !!!
Im so sorry but old problem is over :cry:
can you please please help me on this one :cry:
Yeah well, then mention your FCI (in both Threads), and post some mini-Update in the old Thread (+ sharing your Solution hopefully)... and "maybe" you won't have to wait for 1.5 years for this one, ah-ah...! :wink:

But what you want in this one is not very complicated..., nearly a bit "surprising" for sbd who's been using iMacros for (at least) 1.5 years already, and it has already been asked (and answered) many times on the Forum... :?
- (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...
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 » Wed Jul 04, 2018 3:46 pm

Im using windows 7_64 bit
iMacros Browser (x86) Version 12.0.501.6698
I also hope i can run same script on Macros for Chrome 10.0.2 - VERSION BUILD=1002
I have not used the tool long time honestly
I looked for a solution to my problem and tried to solve it myself
Image
I searched a lot in Google it's just didn't work
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 » Wed Jul 04, 2018 4:43 pm

loverdo wrote:Im using

Code: Select all

windows 7_64 bit
iMacros Browser (x86) Version 12.0.501.6698
I also hope i can run same script on Macros for Chrome 10.0.2 - VERSION BUILD=1002
I have not used the tool long time honestly
I looked for a solution to my problem and tried to solve it myself
Image
I searched a lot in Google it's just didn't work
OK, previous Thread updated, and we finally have your FCI, good...! :D

Yeah, well, using "forum.imacros.net" as Keyword(s) in some Search Engine is a bit like typing "google" in 'Google', ah-ah....!! :roll:
But OK, never mind...

OK, concerning your Qt/Scenario, hum, URL not mentioned and no Script posted, (and you've truncated the Source Code of the Page a bit "too much", ah-ah...!), I can only give you some "generic" Advice, but the same Method should work in all Browsers/Versions, I would think...

=> Use the 'Full HTML' Mode (or I think it's called "Expert Mode" in iMB (v12)) to record clicking on a "correct" Link/Button containing this "class='dispo'" Class and keep the 'CLASS' Attribute to (only) tag those Elements, maybe with (a part of) the 'HREF' together, but the Class alone should be enough, I would think, and replace the changing parts from the Date + Time with Wildcards in the 'TXT' ATTR (or remove it completely), + maybe combined with (Negative or Double (...?, I can't see from your truncated Source)) 'Relative Positioning' if you need to tag the Date instead of the Time, as the Link seems to be on the Time but you mentioned the Date...
- (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...
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 » Wed Jul 04, 2018 6:33 pm

Thank you very much for your replay

I used the mode "Use Complete HTML" and recorded a complete loop
I was luck appointment was available at 2018-07-13 11:00, i changed the website :lol:

Code: Select all

VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
URL GOTO=https://fr.google.com/CS/CAS/index.php
TAG POS=2 TYPE=A ATTR=TXT:S’identifier&&HREF:https://fr.google.com/CS/CAS/login.php
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:login_form ATTR=ID:email&&MAXLENGTH:100&&SIZE:60&&NAME:email CONTENT=EMAIL
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:login_form ATTR=ID:pwd&&MAXLENGTH:100&&SIZE:60&&TYPE:password&&NAME:pwd CONTENT=PASSWORD
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:login_form ATTR=CLASS:submit&&TYPE:submit&&VALUE:S’identifier
'TAG POS=4 TYPE=A:BUTTON ATTR=TXT:11:00&&CLASS:full&&TYPE:button // I clicked on a this but the appointment is not available 
TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:00&&ONCLICK:ajaxCall("ajax_form_status",<SP>"https://fr.google.com/CS/CAS/action.php?process=multiconfirm&what=take_appointment&fg_id=4827368&result=2018-07-13+11%3A00&issuer_view=maCAS2fr")&&CLASS:dispo&&HREF:javascript:void(0)&&TYPE:button
TAG POS=1 TYPE=P FORM=NAME:ajax_confirm_action ATTR=TXT:ATTENTION:<SP>Pendant<SP>la<SP>période<SP>de<SP>forte<SP>affluence,<SP>il<SP>est<SP>fortement<SP>recommandé<SP>d*
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:ajax_confirm_action ATTR=ID:ajaxConfirmCall_submit&&STYLE:font-weight:<SP>bold;&&TYPE:submit&&VALUE:Confirmer
But most of the time appointment open like 5m every week so i need to run a script that can hunt appointment when the site open for me
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 » Wed Jul 04, 2018 7:01 pm

loverdo wrote:Thank you very much for your replay

I used the mode "Use Complete HTML" and recorded a complete loop
I was luck appointment was available at 2018-07-13 11:00, i changed the website :lol:

Code: Select all

VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
URL GOTO=https://fr.google.com/CS/CAS/index.php
TAG POS=2 TYPE=A ATTR=TXT:S’identifier&&HREF:https://fr.google.com/CS/CAS/login.php
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:login_form ATTR=ID:email&&MAXLENGTH:100&&SIZE:60&&NAME:email CONTENT=EMAIL
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:login_form ATTR=ID:pwd&&MAXLENGTH:100&&SIZE:60&&TYPE:password&&NAME:pwd CONTENT=PASSWORD
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:login_form ATTR=CLASS:submit&&TYPE:submit&&VALUE:S’identifier
'TAG POS=4 TYPE=A:BUTTON ATTR=TXT:11:00&&CLASS:full&&TYPE:button // I clicked on a this but the appointment is not available 
TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:00&&ONCLICK:ajaxCall("ajax_form_status",<SP>"https://fr.google.com/CS/CAS/action.php?process=multiconfirm&what=take_appointment&fg_id=4827368&result=2018-07-13+11%3A00&issuer_view=maCAS2fr")&&CLASS:dispo&&HREF:javascript:void(0)&&TYPE:button
TAG POS=1 TYPE=P FORM=NAME:ajax_confirm_action ATTR=TXT:ATTENTION:<SP>Pendant<SP>la<SP>période<SP>de<SP>forte<SP>affluence,<SP>il<SP>est<SP>fortement<SP>recommandé<SP>d*
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:ajax_confirm_action ATTR=ID:ajaxConfirmCall_submit&&STYLE:font-weight:<SP>bold;&&TYPE:submit&&VALUE:Confirmer
But most of the time appointment open like 5m every week so i need to run a script that can hunt appointment when the site open for me
Yep, very good..., so this got recorded for a 'full' Appointment:

Code: Select all

'TAG POS=4 TYPE=A:BUTTON ATTR=TXT:11:00&&CLASS:full&&TYPE:button // I clicked on a this but the appointment is not available
Like I mentioned, you can see that iMacros used the 'CLASS:full' to identify it.

And this one got recorded for a 'dispo' Appointment:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:00&&ONCLICK:ajaxCall("ajax_form_status",<SP>"https://fr.google.com/CS/CAS/action.php?process=multiconfirm&what=take_appointment&fg_id=4827368&result=2018-07-13+11%3A00&issuer_view=maCAS2fr")&&CLASS:dispo&&HREF:javascript:void(0)&&TYPE:button
Here, iMacros didn't record the Class (I would expect some 'CLASS:dispo' Attr), but preferred to go for the 'HREF' like I had mentioned with the long 'ONCLICK' Attr, which you can shorten (and you must remove the changing parts anyway) to stg like for example:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:*:*&&ONCLICK:ajaxCall*https://*/CS/CAS/action.php?process=multiconfirm*&&CLASS:dispo&&TYPE:button
Oh...!, yep it did record the 'CLASS:dispo' actually, ah-ah...! Exactly like I said...! Then OK, this one should work already, and will select the first 'dispo' Appointment..., but even simpler, and should work as well:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:*:*&&CLASS:dispo&&TYPE:button
=> To select again the first 'dispo' Appointment...

And if you don't want your Script to select an Appointment at 07h in the morning and prefer to wait until an Appointment becomes available between [11h00-11h59], you can already specify/keep "11" for the Hours:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:*&&CLASS:dispo&&TYPE:button
But hum..., if several Dates might be available and you only want the first "11hxx" Appointment only on a specific Date, you might need to keep a part of the 'ONCLICK' Attr as it is the only place where the Date is mentioned/specified in the "result=2018-07-13..." part, but I guess you should have understood the "Principle", ah-ah...! :wink:
- (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...
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 » Thu Jul 05, 2018 7:09 pm

This command work like a charm, Thank you :mrgreen:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:*&&CLASS:dispo&&TYPE:button
it select the first appointment, I wish i can select a specific date ?, I only need to add ''If Else Statement" to the script, so when the class='dispo' not find in the web page end the script and make a loop again, I would run script to the run 24/7 :lol:

If class='dispo' found and the above command done please run this command :

Code: Select all

TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:ajax_confirm_action ATTR=ID:ajaxConfirmCall_submit
Else, Loop
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 » Thu Jul 05, 2018 9:09 pm

loverdo wrote:This command work like a charm, Thank you :mrgreen:

Code: Select all

TAG POS=1 TYPE=A:BUTTON ATTR=TXT:11:*&&CLASS:dispo&&TYPE:button
it select the first appointment, I wish i can select a specific date ?, I only need to add ''If Else Statement" to the script, so when the class='dispo' not find in the web page end the script and make a loop again, I would run script to the run 24/7 :lol:

If class='dispo' found and the above command done please run this command :

Code: Select all

TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:ajax_confirm_action ATTR=ID:ajaxConfirmCall_submit
Else, Loop
OK, good to hear... (about the first mini-Script/Line "working like a charm"...!) :D

I already gave you the Answer if you want to specify (only) a specific Date, use the 'ONCLICK' Param... For example...:

Code: Select all

SET Pref_Date "2018-07-13"
SET Pref_Time "11"
'>
TAG POS=1 TYPE=A:BUTTON ATTR=TYPE:button&&CLASS:dispo&&ONCLICK:*result=*{{Pref_Date}}*+*&&TXT:{{Pref_Time}}* 
'Pref_Date' can be specified as "2018-07-13", or "07-13", or even just "13" (only the day...!), well "13" can only be a day in a month of course, but would you specify "07" (today is [2018-07-05]), then the Script would select the first Date still available in "07" = the Month...! => on 07-05, 07-06, 07-07 etc..., no Guaranty for the Date that you really want... Just be aware that you can shorten the Date to only the Day for Day>12, or it can always coincide with the Number for a Month, always safer to specify at least Month+Date.
Euh yep indeed, only specifying "20" or "01" or "18" (meant for the day but that can be found in "2018" as well, ah-ah...!) could have some "funny"/"unexpected" Results, oops...! :lol:

Same thing for 'Pref_Time', you can "only" specify "11", then the Script will try to catch the first spot available from [11:00-11:59], or you can specify "11:00" and it will only look for "11:00". (I made sure that if you only specify the Hour, it cannot be used for the Minutes, or the Script could select some "07:11" Spot otherwise...)

(Well, "I made sure"..., yeah, well, I cannot test anything at all as I don't have Access to your Site..., up to the "Best" I can "virtually" think of and how I think the Site might react, of course...! :oops: )

>

And for your other Qt about making the click on the 'SUBMIT' Button, I reckon this Button does nothing if the Spot for the Appointment is not Free/available, then simply use '!ERRORIGNORE' (and a short '!TIMEOUT_STEP') and you are all set, I would think... 8)
No need for any 'IF/ELSE' whatever..., unless you wanted to specify more than only 1 Date and more than only 1 Time/Hour...
Last edited by chivracq on Sun Jul 08, 2018 6:41 pm, edited 1 time in total.
- (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...
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 » Sun Jul 08, 2018 12:03 pm

Thank you very much for your valuable help. I've run the script in the past two days
He worked well, by adding

Code: Select all

SET !ERRORIGNORE yes
SET !TIMEOUT_STEP 5
Now imacros ignore when the appointment if it not available and try again, awesome !! :D

I wonder if i can select a day range in SET?

Code: Select all

SET Pref_Date "2018-07-13"
SET Pref_Time "11"
like tell imacros to pick any available date between 2018-07-18 and 2018-07-29 and pick any available time between 11 and 15?

So I ran the script in the past two days.. checked yesterday and no appointment booked ... I reviewed the script many times and maybe there was something wrong but I did not find anything, especially as it ignored errors... :mrgreen:
I discovered that there a final missing page .. it only shows up when people start booking, so i choise the script to book "2018-07-13" but people booked before me and all slots is full .... didn't think at that before :shock:

I believe that this is the code :

Code: Select all

        var dt4  = '2018-07-09';
        var blocked_dates = ["28-12-2017","29-12-2017","01-01-2018","30-03-2018","02-04-2018","01-05-2018","01-06-2018","15-08-2018","12-10-2018"];
        var available_dates = ["16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"];
        var fullCapicity_dates = ["09-07-2018","10-07-2018","11-07-2018","12-07-2018","13-07-2018",];
        var offDates_dates = ["14-07-2018","15-07-2018","21-07-2018","22-07-2018","24-07-2018","28-07-2018","29-07-2018"];
Now the date "2018-07-13" is in "var fullCapicity_dates" so it's booked
this is the full source

Code: Select all

<script type="text/javascript">
	var today = new Date();
	var dd = today.getDate()+1;
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();
	if(dd<10){
		dd='0'+dd
	} 
	if(mm<10){
		mm='0'+mm
	} 
	var today = yyyy+'-'+mm+'-'+dd;
	function formatDate(rawDate) {
	  var day = ("0" + rawDate.getDate()).slice(-2);
	  var month = ("0" + (rawDate.getMonth() + 1)).slice(-2);
	  return (day)+ "-" + (month)+ "-" +rawDate.getFullYear() ;
	}		
	$(document).ready(function() {
		var dt1  = '2018-07-08';
			 $('.date_of_birth').datepicker({
					format: "yyyy-mm-dd",
					endDate: new Date(dt1),
					startDate: '-100y',
					autoclose: true,
					startView: 2
			  });
			  $('.pptIssueDate').datepicker({
					format: "yyyy-mm-dd",
					endDate: new Date(dt1),
					startDate: '-100y',
					autoclose: true,
					startView: 2
				});
			  $('.passport_validate_till').datepicker({
					format: "yyyy-mm-dd",
					startDate: new Date(dt1),
					autoclose: true,
					startView: 2
			  });
		var dt4  = '2018-07-09';
		var blocked_dates = ["28-12-2017","29-12-2017","01-01-2018","30-03-2018","02-04-2018","01-05-2018","01-06-2018","15-08-2018","12-10-2018"];
		var available_dates = ["13-07-2018","16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"];
		var fullCapicity_dates = ["09-07-2018","10-07-2018","11-07-2018","12-07-2018"];
		var offDates_dates = ["14-07-2018","15-07-2018","21-07-2018","22-07-2018","24-07-2018","28-07-2018","29-07-2018"];
		$('.app_date').datepicker({
			language: "en",
			Default: true,
			format: "yyyy-mm-dd",
			startDate: new Date(dt4),
			endDate: '2018-12-31', 
			autoclose: true,
			forceParse:true,
			startView: 0,
			beforeShowDay: function(date){
				   var formattedDate = formatDate(date);
				   if ($.inArray(formattedDate.toString(), blocked_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'inactiveClass',
						  tooltip: 'Holiday'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), available_dates) != -1){
					   return {
						  enabled : true,
						  classes: 'activeClass',
						  tooltip: 'Book'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), fullCapicity_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'fullcap',
						  tooltip: 'Slots Full'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), offDates_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'offday',
						  tooltip: 'Off Day'
					   };
				   }
				   
					return {
					  enabled : false,
					  tooltip: 'Not Allowed'
				   };
				  return;
			  }
	    });
		$("#app_date").datepicker("setDate", '2016-09-16');
       
	     
	});
	
	
	
</script>
</div>
So i recorded again to choise "16-07-2018" from "var available_dates"
Because i need a new script for this new page
This is the automatic mode :

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=2 TYPE=TD ATTR=TXT:16


But when i play it it does not choise it and i get this error :

Code: Select all

Error -1300: Cannot find HTML element of type "TD:" with attribute(s) "TXT:27".. Line 7: TAG POS=2 TYPE=TD ATTR=TXT:27
i tried this :
I start recording choising the date "2018-07-18" then i went back and choise "2018-07-27"
To see if there is any change :lol: but nothing new in the automatic mode :x
I change the recording mode to complete HTML :mrgreen:
and i noticed a change, SOMETHING NEW !! "CONTENT=2018-07-18"

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=TD ATTR=TXT:18
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT=2018-07-18
TAG POS=2 TYPE=TD ATTR=TXT:27
and yeeeeees by playing :

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT=2018-07-27
It's working :D Ok i feel like i'm very smart right now :mrgreen:
And by combinnig the code from automatic and html mode, wow great ideas :D
Now i want run 2 script the first one with day range and last one also with day range :idea:
But i want to twist this final code to also do a days range to pick any date Between 17-07 and 26-07 in var available_dates and skip the first 2 date (16-07 and 17-07) ? :cry:
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 » Sun Jul 08, 2018 10:34 pm

loverdo wrote:Thank you very much for your valuable help. I've run the script in the past two days
He worked well, by adding

Code: Select all

SET !ERRORIGNORE yes
SET !TIMEOUT_STEP 5
Now imacros ignore when the appointment if it not available and try again, awesome !! :D

I wonder if i can select a day range in SET?

Code: Select all

SET Pref_Date "2018-07-13"
SET Pref_Time "11"
like tell imacros to pick any available date between 2018-07-18 and 2018-07-29 and pick any available time between 11 and 15?

So I ran the script in the past two days.. checked yesterday and no appointment booked ... I reviewed the script many times and maybe there was something wrong but I did not find anything, especially as it ignored errors... :mrgreen:
I discovered that there a final missing page .. it only shows up when people start booking, so i choise the script to book "2018-07-13" but people booked before me and all slots is full .... didn't think at that before :shock:

I believe that this is the code :

Code: Select all

        var dt4  = '2018-07-09';
        var blocked_dates = ["28-12-2017","29-12-2017","01-01-2018","30-03-2018","02-04-2018","01-05-2018","01-06-2018","15-08-2018","12-10-2018"];
        var available_dates = ["16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"];
        var fullCapicity_dates = ["09-07-2018","10-07-2018","11-07-2018","12-07-2018","13-07-2018",];
        var offDates_dates = ["14-07-2018","15-07-2018","21-07-2018","22-07-2018","24-07-2018","28-07-2018","29-07-2018"];
Now the date "2018-07-13" is in "var fullCapicity_dates" so it's booked
this is the full source

Code: Select all

<script type="text/javascript">
	var today = new Date();
	var dd = today.getDate()+1;
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();
	if(dd<10){
		dd='0'+dd
	} 
	if(mm<10){
		mm='0'+mm
	} 
	var today = yyyy+'-'+mm+'-'+dd;
	function formatDate(rawDate) {
	  var day = ("0" + rawDate.getDate()).slice(-2);
	  var month = ("0" + (rawDate.getMonth() + 1)).slice(-2);
	  return (day)+ "-" + (month)+ "-" +rawDate.getFullYear() ;
	}		
	$(document).ready(function() {
		var dt1  = '2018-07-08';
			 $('.date_of_birth').datepicker({
					format: "yyyy-mm-dd",
					endDate: new Date(dt1),
					startDate: '-100y',
					autoclose: true,
					startView: 2
			  });
			  $('.pptIssueDate').datepicker({
					format: "yyyy-mm-dd",
					endDate: new Date(dt1),
					startDate: '-100y',
					autoclose: true,
					startView: 2
				});
			  $('.passport_validate_till').datepicker({
					format: "yyyy-mm-dd",
					startDate: new Date(dt1),
					autoclose: true,
					startView: 2
			  });
		var dt4  = '2018-07-09';
		var blocked_dates = ["28-12-2017","29-12-2017","01-01-2018","30-03-2018","02-04-2018","01-05-2018","01-06-2018","15-08-2018","12-10-2018"];
		var available_dates = ["13-07-2018","16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"];
		var fullCapicity_dates = ["09-07-2018","10-07-2018","11-07-2018","12-07-2018"];
		var offDates_dates = ["14-07-2018","15-07-2018","21-07-2018","22-07-2018","24-07-2018","28-07-2018","29-07-2018"];
		$('.app_date').datepicker({
			language: "en",
			Default: true,
			format: "yyyy-mm-dd",
			startDate: new Date(dt4),
			endDate: '2018-12-31', 
			autoclose: true,
			forceParse:true,
			startView: 0,
			beforeShowDay: function(date){
				   var formattedDate = formatDate(date);
				   if ($.inArray(formattedDate.toString(), blocked_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'inactiveClass',
						  tooltip: 'Holiday'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), available_dates) != -1){
					   return {
						  enabled : true,
						  classes: 'activeClass',
						  tooltip: 'Book'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), fullCapicity_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'fullcap',
						  tooltip: 'Slots Full'
					   };
				   }
				   if ($.inArray(formattedDate.toString(), offDates_dates) != -1){
					   return {
						  enabled : false,
						  classes: 'offday',
						  tooltip: 'Off Day'
					   };
				   }
				   
					return {
					  enabled : false,
					  tooltip: 'Not Allowed'
				   };
				  return;
			  }
	    });
		$("#app_date").datepicker("setDate", '2016-09-16');
       
	     
	});
	
	
	
</script>
</div>
So i recorded again to choise "16-07-2018" from "var available_dates"
Because i need a new script for this new page
This is the automatic mode :

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=2 TYPE=TD ATTR=TXT:16


But when i play it it does not choise it and i get this error :

Code: Select all

Error -1300: Cannot find HTML element of type "TD:" with attribute(s) "TXT:27".. Line 7: TAG POS=2 TYPE=TD ATTR=TXT:27
i tried this :
I start recording choising the date "2018-07-18" then i went back and choise "2018-07-27"
To see if there is any change :lol: but nothing new in the automatic mode :x
I change the recording mode to complete HTML :mrgreen:
and i noticed a change, SOMETHING NEW !! "CONTENT=2018-07-18"

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=TD ATTR=TXT:18
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT=2018-07-18
TAG POS=2 TYPE=TD ATTR=TXT:27
and yeeeeees by playing :

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT=2018-07-27
It's working :D Ok i feel like i'm very smart right now :mrgreen:
And by combinnig the code from automatic and html mode, wow great ideas :D
Now i want run 2 script the first one with day range and last one also with day range :idea:
But i want to twist this final code to also do a days range to pick any date Between 17-07 and 26-07 in var available_dates and skip the first 2 date (16-07 and 17-07) ? :cry:
Woaw...!, you made some great Progress, ah-ah...! 8)

Hum, "funny" to notice that the Programmer of the Page couldn't spell "Capacity" correctly in 'fullCapicity_dates', oops...!

But, OK..., well..., this getting "Interesting", ah-ah...!
=> You want to be able to specify a Date Range instead of only 1 Date, OK, why not, everything is possible...

All available Dates are contained in the Script in:

Code: Select all

var available_dates = ["13-07-2018","16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"];
=> You can extract them probably using stg like:

Code: Select all

SET !EXTRACT NULL
TAG POS=1 TYPE=SCRIPT ATTR=TXT:*available_dates* EXTRACT=TXT
OK, I guess I was little bit "bored" on this sunny Sunday afternoon, ah-ah...!, (I had some funny big Party until a bit late last night, so I staid a bit quietly at home today... :oops: ), and I did a bit of Testing, on this current Page of your Thread where you've posted the Script containing this 'available_dates' Array, and that would give already stg like:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1

SET Start_Date "18-07-2018"
SET End_Date "25-07-2018"
'>
SET Default_Start_Date YES
SET Default_End_Date YES

'URL GOTO=https://forum.imacros.net/viewtopic.php?f=2&t=29543
'TAG POS=1 TYPE=CODE ATTR=TXT:var<SP>dt4<SP>=<SP>'2018-07-09';<SP>var<SP>blocked_dates*

SET !EXTRACT NULL
TAG POS=1 TYPE=CODE ATTR=TXT:var<SP>dt4<SP>=<SP>'2018-07-09';<SP>var<SP>blocked_dates* EXTRACT=TXT
SET Avail_Dates EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('available_dates = '); y=x[1].split(';'); z=y[0]; z;")
SET Avail_Dates_Arr EVAL("var ad='{{Avail_Dates}}'; var x,y,z; x=ad.split('['); y=x[1].split(']'); z=y[0].split('\"').join(''); z;")
SET Count_Avail_Dates EVAL("var ada='{{Avail_Dates_Arr}}'; var x,y,z; x=ada.split(','); z=x.length; z;")
'>
SET Avail_Date_2 EVAL("var ad='{{Avail_Dates}}'; var x,y,z; x=ad.split('\"'); z=x[3]; z;")
SET Avail_Date_3 EVAL("var ada='{{Avail_Dates_Arr}}'; var x,y,z; x=ada.split(','); z=x[2]; z;")

PROMPT EXTRACT:<BR>{{!EXTRACT}}
'SET Debug_Msg EXTRACT:<BR>{{!EXTRACT}}<BR><BR>
SET Debug_Msg Available_Dates:<BR>_{{Avail_Dates}}_<BR><BR>Available_Dates_Array:<BR>_{{Avail_Dates_Arr}}_
ADD Debug_Msg <BR><BR>Count_Available_Dates:<SP>_{{Count_Avail_Dates}}_
'ADD Debug_Msg <BR><BR>Available_Date_2:<SP>_{{Avail_Date_2}}_<BR>Available_Date_3:<SP>_{{Avail_Date_3}}_<BR><BR>
'PROMPT {{Debug_Msg}}

SET Start_Date_Idx_Real EVAL("var ada='{{Avail_Dates_Arr}}', sd='{{Start_Date}}'; var x,y,z; x=ada.split(','); if(sd==''){z=-1;} else{z=x.indexOf(sd);}; z;")
SET Start_Date_Idx EVAL("var sdir='{{Start_Date_Idx_Real}}', dsd='{{Default_Start_Date}}'; var x,y,z; if((sdir==-1)&&(dsd=='YES')){z=0;} else if(sdir>=0){z=sdir;} else{MacroError('{{Debug_Msg}}');}; z;")

SET End_Date_Idx_Real EVAL("var ada='{{Avail_Dates_Arr}}', ed='{{End_Date}}'; var x,y,z; x=ada.split(','); if(ed==''){z=-1;} else{z=x.indexOf(ed);}; z;")
SET End_Date_Idx EVAL("var edir='{{End_Date_Idx_Real}}', ded='{{Default_End_Date}}', cad='{{Count_Avail_Dates}}'; var x,y,z; if((edir==-1)&&(ded=='YES')){z=cad-1;} else if(edir>=0){z=edir;} else{MacroError('{{Debug_Msg}}');}; z;")

SET Modulo_Dates EVAL("var sdi='{{Start_Date_Idx}}', edi='{{End_Date_Idx}}'; var x,y,z; z=edi*1-sdi*1+1; z;")
SET Date_Range_Arr EVAL("var ada='{{Avail_Dates_Arr}}', sdi='{{Start_Date_Idx}}', edi='{{End_Date_Idx}}'; var x,y,z; x=ada.split(','); y=x.slice(sdi,edi*1+1); z=y.join('\",\"'); z;")
SET Date_Range ["{{Date_Range_Arr}}"]

ADD Debug_Msg Start_Date:<SP>_{{Start_Date}}_<BR>Default_Start_Date:<SP>_{{Default_Start_Date}}_
ADD Debug_Msg <BR>End_Date:<SP>_{{End_Date}}_<BR>Default_End_Date:<SP>_{{Default_End_Date}}_
ADD Debug_Msg <BR><BR>Start_Date_Index_Real:<SP>_{{Start_Date_Idx_Real}}_<SP>('-1'='Not_Found')<BR>Start_Date_Index:<SP>_{{Start_Date_Idx}}_
ADD Debug_Msg <BR>End_Date_Index_Real:<SP>_{{End_Date_Idx_Real}}_<SP>('-1'='Not_Found')<BR>End_Date_Index:<SP>_{{End_Date_Idx}}_
ADD Debug_Msg <BR><BR>Modulo_Dates:<SP>_{{Modulo_Dates}}_
ADD Debug_Msg <BR>Date_Range:<BR>_{{Date_Range}}_
PROMPT {{Debug_Msg}}
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)

You need to specify the Full Date for 'Start_Date' and 'End_Date' ("18-07-2018" for example), exactly like it will be found in the Array from the Script on the Site, if it's an empty String ("") or only "18-07", it will return "-1" (=Not Found), and you use the 'Default_Start_Date' and 'Default_End_Date' Mechanisms (=> "YES"), it will use automatically the First and the Last Dates available...

Result in the 'PROMPT':
Available_Dates:
_["16-07-2018","17-07-2018","18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018","26-07-2018"]_

Available_Dates_Array:
_16-07-2018,17-07-2018,18-07-2018,19-07-2018,20-07-2018,23-07-2018,25-07-2018,26-07-2018_

Count_Available_Dates: _8_Start_Date: _18-07-2018_
Default_Start_Date: _YES_
End_Date: _25-07-2018_
Default_End_Date: _YES_

Start_Date_Index_Real: _2_ ('-1'='Not_Found')
Start_Date_Index: _2_
End_Date_Index_Real: _6_ ('-1'='Not_Found')
End_Date_Index: _6_

Modulo_Dates: _5_
Date_Range:
_["18-07-2018","19-07-2018","20-07-2018","23-07-2018","25-07-2018"]_
Not completely finished to integrate with your existing Script, but the rest is fairly easy..., and you will use the 'Modulo' Var to loop your Script "Modulo" that Var, ah-ah...!, => for '!LOOP'=6 in this Example with 5 available Dates in the 'Date_Range', it will start again with the 1st Date...

I guess that already gives you an Idea..., and similarly for the Time..., maybe using some Nested Modulo Loop for the available Times for each Day... 8)

EDIT:
Added (x2) the "var x,y,z;" Var Declaration for the 2 'xxx._Date_Idx' Vars... (Not required on FF, but iMB is less tolerant...)
Last edited by chivracq on Mon Jul 09, 2018 11:31 am, edited 1 time in total.
- (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...
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 » Mon Jul 09, 2018 9:51 am

i'm so sorry i feel so stupid
this is super complicated for me I spent all night trying to run your script but no luck
Can i have your brain for 5 minutes :mrgreen:

When i run

Code: Select all

 SET !EXTRACT NULL
TAG POS=1 TYPE=SCRIPT ATTR=TXT:*available_dates* EXTRACT=TXT
Why i's extract a big code intead of just available_dates var content ?

The script stop at this line :

Code: Select all

Error -1250: JScript statement in EVAL contains the following error: Object required. Line 17: SET Avail_Dates EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('available_dates = '); y=x[1].split(';'); z=y[0]; z;")
when i set ERRORIGNORE

Code: Select all

EXTRACT:
#EANF #
Untitledaaa.png
same thing in forum and original websites date ranges never shows up, I modify the var dt4 to * because like for today it's have changed

Code: Select all

TAG POS=1 TYPE=CODE ATTR=TXT:var<SP>dt4<SP>=<SP>'*';<SP>var<SP>blocked_dates* EXTRACT=TXT
But i know that the final command is : and it's will change any date from it randomly right

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT={{Date_Range}}
Last edited by loverdo on Mon Jul 09, 2018 12:08 pm, edited 1 time in total.
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 » Mon Jul 09, 2018 11:23 am

loverdo wrote:i'm so sorry i feel so stupid
this is super complicated for me I spent all night trying to run your script but no luck
Can i have your brain for 5 minutes :mrgreen:

When i run

Code: Select all

 SET !EXTRACT NULL
TAG POS=1 TYPE=SCRIPT ATTR=TXT:*available_dates* EXTRACT=TXT
Why i's extract a big code intead of just available_dates var content ?
Yeah, well..., I knew it was a little bit "High Level", that's why I found it "Interesting" to "play" with it, and to write that Script myself, ah-ah...! (I very rarely write Scripts for other Users...)

But yep, normal about the "big code", the 'EXTRACT' will extract the whole Content of that Script on your Page, the "TXT:*available_dates*" is only meant to identify/locate it because I know it contains the "available_dates" String in it...
It's the 'EVAL()' afterwards that should isolate the Array containing the Dates from the whole Script/Extract...
loverdo wrote: The script stop at this line :

Code: Select all

Error -1250: JScript statement in EVAL contains the following error: Object required. Line 17: SET Avail_Dates EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('available_dates = '); y=x[1].split(';'); z=y[0]; z;")
when i set ERRORIGNORE

Code: Select all

EXTRACT:
#EANF #
Image
Hum..., never seen that "Object required." RuntimeError... I can only test on the Forum Page as I cannot access your "real" Page...
You can try posting the whole Content in the 'EXTRACT' that you get in the '!EXTRACT_TEST_POPUP' in some raw ']CODE[' Tag in your Thread...

And hum, I see I forgot some "var x,y,z;" Declaration in the 2 'xxx_Date_Idx' 'EVAL()' Statement, they are not needed on FF, but iMB doesn't like it, I think I remember... I will edit my previous Post after posting this one...

Hum, and when posting some Screenshot, you can better upload it directly to the Forum, most Links on external Image Hosting Sites get broken after a while as those Sites disappear or go commercial or clean the Data every few weeks/months or even years...
loverdo wrote:same thing in forum and original websites date ranges never shows up, I modify the var dt4 to * because like for today it's have changed

Code: Select all

TAG POS=1 TYPE=CODE ATTR=TXT:var<SP>dt4<SP>=<SP>'*';<SP>var<SP>blocked_dates* EXTRACT=TXT
But i know that the final command is : and it's will change any date from it randomly right

Code: Select all

TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:app_date CONTENT={{Date_Range}}
Yeah, well, you cannot reuse directly the 'Date_Range' Var in your 'INPUT' Field...
That Var is actually only meant for the 'PROMPT', to re-display the Dates that the Script will be using one by one at each Loop, in the same Format like the original Array from the Script. You will need to use a similar Mechanism like I did for 'Date_Avail_2' and '_3' to isolate them one by one.

It could work with 'Date_Range_Arr' (not displayed in the 'PROMPT') if your Date Range only contains 1 Date, but you would still need to reverse the Format from 'dd-mm-yyyy' to 'yyyy-mm-dd' like expected by the 'INPUT' Field if I remember correctly... (I didn't check the previous Posts in the Thread, but I noticed such a "Reverse Format" Mechanism in the JS Script you want to extract...)

>>>

Hum, and mini-Remark, the big Banner in your Sig is "funny" for a short while, but a bit "annoying" after that, when "working" on the Thread...
I will block that Image/Site (for myself, ah-ah...!) if you want to keep it in your Sig... :wink:
- (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 » Thu Jul 12, 2018 3:33 pm

And...?, any "Progress", 3 days later...?

(Oh..., and Thanks for removing the Banner in your Sig, was getting a bit annoying indeed, ah-ah...! :wink: )
- (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