Conditional statement to check value of HTML tag

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
Post Reply
paulwhit
Posts: 4
Joined: Mon Dec 07, 2020 2:50 am

Conditional statement to check value of HTML tag

Post by paulwhit » Fri Jan 15, 2021 2:25 am

Hi,

I would like to create a macro that contains a conditional statement to check the value of a HTML tag on a webpage:

Checks TAG POS=1 TYPE=DIV ATTR=ID:Vop11
If this = "Booked"
Refresh webpage
Else
Continue running macro

I am using iMacros 12.5 Enterprise on Windows 10 and running the macro in iMacros Browser.

I am new to iMacros and any solutions would be appreciated.

Many thanks,

Paul
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional statement to check value of HTML tag

Post by chivracq » Fri Jan 15, 2021 3:05 am

paulwhit wrote:
Fri Jan 15, 2021 2:25 am
Hi,

I would like to create a macro that contains a conditional statement to check the value of a HTML tag on a webpage:

Code: Select all

Checks TAG POS=1 TYPE=DIV ATTR=ID:Vop11
If this = "Booked"
Refresh webpage
Else
Continue running macro
I am using

Code: Select all

iMacros 12.5 Enterprise on Windows 10 and running the macro in iMacros Browser.
I am new to iMacros and any solutions would be appreciated.

Many thanks,

Paul

Oh...!?, good...!, you "finally" mention your FCI, and manage to spell "iMacros" correctly... :D
FCI not mentioned was the Reason I had not reacted to your 1st Thread, you may want to improve the "Quality" of that Thread and bump it if you are still looking for Help or share the "Solution" if you managed to solve it by yourself, to make that Thread also useful for other Users... :idea:

>>>

Then hum, iMB v12.5 'Enterprise' is a bit of a "strange" Version to be using for someone who's "new to iMacros", as "current" Version is now v12.6 and v12.5 has been around for more than 2 years (released in Novb 2018), and iMB 'Enterprise' is "meant" for Professional Programmers to be able to use your "favorite" Programming Language with the iMacros 'SI' ('Scripting Interface')...

And the Scenario/Workflow you are describing sounds like some very "Basic" Functionality that you want with iMacros to me and should be pretty easy to implement for any "Professional" Programmer in their "favorite" Prog Language, I would think..., which is apparently your "Plan" as you opened your Thread in the 'Scripting Interface' Sub-Forum... :o
(Although this can also be implemented in pure '.iim'...)

So what is your Prog Language...?, and what have you tried...?, where do you get stuck...?
And your Scenario has btw already been asked and covered many times, if you search the Forum a bit, you'll find many relevant/similar Threads... :idea:

And hum, if you are using iMB 'Enterprise', you probably have direct Access to @TechSup through your 'Enterprise' License, they'll probably be "more" willing to help you and to write your Code or give you some Example(s) than the Forum which is more (Advanced) Users helping Users after they've tried "their Best" and "really" get stuck... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Tom, Tech Support
Posts: 3675
Joined: Mon May 31, 2010 4:59 pm

Re: Conditional statement to check value of HTML tag

Post by Tom, Tech Support » Fri Jan 15, 2021 4:13 pm

I'm curious chivracq, how would YOU do a conditional REFRESH using macro code alone?
Regards,

Tom, iMacros Support
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional statement to check value of HTML tag

Post by chivracq » Fri Jan 15, 2021 4:36 pm

Tom, Tech Support wrote:
Fri Jan 15, 2021 4:13 pm
I'm curious chivracq, how would YOU do a conditional REFRESH using macro code alone?

2 Ways, ah-ah...! :twisted:

1- A Conditional 'URL GOTO' to reload the Page if the Page has its own URL. :idea:

2- Splitting the whole Workflow of the Script into several Parts/'.iim' Macros to Conditionally Launch the desired "next" '.iim' Macro (that will contain the 'REFRESH') + also call in return the next Part/Macro, using the 'URL GOTO=imacros://run/?m=' Syntax. :idea:

And a 3rd Way will be "one day" possible when my Enhancement Request for Item 14 will hopefully have been implemented...!: :P :wink:
chivracq wrote:
Fri Mar 23, 2018 2:24 pm
-14- Implement a "Super" Built-in Var that could contain Commands like 'OPEN' / 'CLOSE' / 'REFRESH' / 'CLEAR' / etc and other (Built-in) Vars like for example in '{{!COL{{!LOOP}}}}'.
>>>

EDIT_1:
Oh...!, and a 3rd Way anyway: :twisted:
3- A Conditional 'TAB' to stay on 'TAB_1' or switch to a 'TAB_2' (already opened on some Local '.html' or '.txt' Page or some dummy 'google.com' Page), where the 'REFRESH' will refresh that dummy Page on 'TAB_2' before going back to 'TAB_1'... :idea:

That Technique can also be used to (conditionally) "mute" complete Sections of a Script, especially if the Script contains Commands that cannot be computed with 'EVAL()' like 'REFRESH' indeed for example as there is no 'GOTO' Command in iMacros (another of my EnhReq's btw, ah-ah...! :P ) and where the Code from the Section to mute won't do anything on the dummy Tab/Page... :idea:

>>>

EDIT_2:
And another one, ah-ah...!: :twisted:
4- A Conditional Call to the 'reload()' JS Method using the 'URL GOTO=javascript' Syntax... :idea:

>>>

EDIT_3:
Oh...!?!, and one more, Total is now at 5, ah-ah...!: :twisted: :P
5- A Conditional 'Ctrl^r' using the 'EVENT' Mode, ah-ah...!
=> With the Computed Result on the 'CHAR' Param with "r"/"" (Empty String), or any other Letter that doesn't trigger some "valid" Shortcut with 'Ctrl'...
=> Or on the 'MODIFIERS' Param with "Ctrl"/"Alt", 'Alt^r' does nothing, but not with "Shift" as 'Shift^r' still triggers a Forced Refresh bypassing the Browser Cache...
Last edited by chivracq on Tue Jan 19, 2021 3:36 am, edited 3 times in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
paulwhit
Posts: 4
Joined: Mon Dec 07, 2020 2:50 am

Re: Conditional statement to check value of HTML tag

Post by paulwhit » Fri Jan 15, 2021 10:00 pm

Thanks for your advice. I would like to implement this purely in iim using a Conditional 'URL GOTO' to check if TAG POS=1 TYPE=DIV ATTR=ID:Vop11 = 'Booked' and then use REFRESH if the tag doesn't = "Booked". Please could you advise on how to write this. I've searched the form bu I can't find any examples of conditional statements that check a HTML tag.
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional statement to check value of HTML tag

Post by chivracq » Sat Jan 16, 2021 3:16 am

paulwhit wrote:
Fri Jan 15, 2021 10:00 pm
Thanks for your advice. I would like to implement this purely in iim using a Conditional 'URL GOTO' to check if TAG POS=1 TYPE=DIV ATTR=ID:Vop11 = 'Booked' and then use REFRESH if the tag doesn't = "Booked". Please could you advise on how to write this. I've searched the form bu I can't find any examples of conditional statements that check a HTML tag.

"I would like to implement this purely in iim"
=> Hum OK, [perfect for the quick Follow-up btw :D ], => yep, feasible like I demonstrated/explained (x4), and it was your "Lucky Day", I wouldn't have explained those 4 Techniques if @TechSup hadn't asked, ah-ah...! :wink: , [hum, apparently they didn't know either how to do that in pure '.iim', oops-ah-ah...! :shock: ], but hum, why did you open your Thread in the 'SI' Sub-Forum then, if you want to implement that Func in pure '.iim' and don't want to use the 'SI'...? :? :roll:
=> @Forum Admin, then I guess the Thread now rather belongs to the 'Data Extraction' Sub-Forum than the 'SI' one...? :wink:

"I've searched the form" => Well, search the FORUM maybe instead of some "form" and maybe you'll find what you are looking for, if you don't put a Typo everywhere, ah-ah...! :idea: :roll:
... And the 'Data Extraction' Sub-Forum is a good place to start looking for similar/relevant Threads... :idea:
... And simply searching on "conditional+refresh" already yields pretty relevant Threads, I would think...! :idea:

>>>

And you didn't react about using iMB v12.5 but being "new to iMacros"..., any Explanation...?
Nor about updating your first Thread and finishing it "neatly" and useful for other Users...?
(I'm pretty Advanced also in Shadoks Communication, if you are wondering... :idea: :wink: )
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 9693
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional statement to check value of HTML tag

Post by chivracq » Mon Jan 18, 2021 1:25 am

Hum, I guess we won't get much Follow-up (anymore) from @OP as they seem to rather seek their "Luck" on SOF... OK, fair enough... :|

For those "Interested", Parallel Thread on SOF:
- iMacros conditional statement to check value of HTML tag
Low Quality, FCI not even mentioned, (=> already got a (-1) from me...), no Replies (yet)...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Tom, Tech Support
Posts: 3675
Joined: Mon May 31, 2010 4:59 pm

Re: Conditional statement to check value of HTML tag

Post by Tom, Tech Support » Mon Jan 18, 2021 4:40 pm

chivracq wrote:
Sat Jan 16, 2021 3:16 am
I wouldn't have explained those 4 Techniques if @TechSup hadn't asked, ah-ah...! :wink: , [hum, apparently they didn't know either how to do that in pure '.iim', oops-ah-ah...! :shock: ]
I did not realize until now that you could specify an empty value to URL GOTO, which essentially results in a no-op:

Code: Select all

URL GOTO=
I would have thought that this would raise an error (hmmm, maybe it should?). So now I understand how you could use a 'conditional' URL GOTO (using the EVAL command of course to derive the value, or lack thereof), very clever!
Regards,

Tom, iMacros Support
paulwhit
Posts: 4
Joined: Mon Dec 07, 2020 2:50 am

Re: Conditional statement to check value of HTML tag

Post by paulwhit » Mon Jan 18, 2021 6:10 pm

Many thanks for your help, chivracq and Tom. I've found the solution using the code in this thread: viewtopic.php?t=25762#p67692 :D

SOF thread now removed :)
Post Reply