Clarify use of the ExtractTag please.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Clarify use of the ExtractTag please.

Post by tommytx » Thu Jul 13, 2006 6:23 am

Let's say I use the recorder tag extract wizard and it tells me that what I am looking for is "INPUT" and 9. I assume that is the 9th input tag in the file. How do I use that info. As you can see I have probably filled it in all screwed up below.
Also how do you access what is extracted, is it in the "t" variable, or in the "ExtractTag" variable?

Of course what I have done below does not work, but please help.


******************* Begin Code ********************

'This function extracts text from a specific tag by name and index
'e.g. TABLE,0 (1st Table element) or P,1 (2nd Paragraph element)
'set all to 1 to extract all HTML, 0 for only inside text without HTML
Function ExtractTag(TagName,Num,all)
dim t
set t = IE.document.getElementsbyTagname(Tagname)
if all=1 then
ExtractTag = t.Item(Num).outerHTML
else
ExtractTag = t.Item(Num).innerText
end if
End Function

VBEND

VBRun>CreateIE
VBRun>Navigate,C:\_linkmetro_now\_ask_for_link_new\test.htm
Wait>1
VBRun>WebFormFill,id,Marcus,0

VBRun>ExtractTag,INPUT,9,1 ?????????
MessageModal>%ExtractTag% ?????????
MessageModal>%t% ?????????

******************** End of Code *******************

One lost puppy.
The fill form portion works fine, but I am totally lost in regard to the extract tag.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 13, 2006 7:07 am

WebRecorder will show you - Using the Tag Extraction wizard just press Insert and it will insert the code for you.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Thu Jul 13, 2006 3:17 pm

I got the code from webrecorder as I explained above, but I am trying to use the Vbscript version above that you show an example of. I want to use it without the webrecorder command "LibFunc>" so the command will be different, only the tag name will be the same.

Below is the wizard code and I can see:
tagname=INPUT
num=9
How do I apply it to the vbscript example?

//Modify buffer size if required ...
Let>INPUT9_SIZE=4098
LibFunc>hIE,ExtractTag,r,%IE[0]%,,INPUT,9,0,INPUT9
MidStr>r_6,1,r,INPUT9

Are these commands correct based on the wizard and converting to the vbscript version below? I do not want to use LibFunc>

VBRun>ExtractTag,INPUT,9,1 ?????????
MessageModal>%ExtractTag% ?????????
MessageModal>%t% ?????????

And again, how do I capture the extract info, what variable is it located in so I can get it?

Sorry if I poorly explained the question.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 13, 2006 5:04 pm

Sorry. You want:

VBEval>ExtractTag("INPUT",9,1),thetext

The result is now in the variable thetext.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Thu Jul 13, 2006 5:31 pm

Thanks you are the best, I worked all night trying to find a solution and you did it with one line. Now I am pulling the outerHTML just fine.

When I use the VBEval>ExtractTag("INPUT",9,1),thetext I get the outer html just fine.

But when I use VBEval>ExtractTag("INPUT",9,0),thetext I get no return at all in thetext variable.

I will keep working on this one on my own as I know you are busy.

Is the syntax you show above listed anywhere, i can't seem to find that sort of detailed breakdown anywhere. If all the syntax was listed somewhere, we wouldn't have to bother you so much... I suppose if I studied a huge vbscript manual I might find it..Huh?

Here is what I am using:

(Works great) *********************************
VBEval>ExtractTag("INPUT",0,1),thetext
MessageModal>Here is the Long answer -> %thetext%.

(Resulting message)
Here is the Long answer -> .

(Returns a Blank) ******************************
VBEval>ExtractTag("INPUT",0,0),thetext
MessageModal>Here is the short answer -> %thetext%.

(Resulting message)
Here is the short answer -> .

The inner should have pulled out "Marcus" do I need to use the "Midstr" command to get the inner.

I am repeating the function below so you can inspect to see if I am missing anything.

Function ExtractTag(TagName,Num,all)
dim t
set t = IE.document.getElementsbyTagName(Tagname)
if all=1 then
ExtractTag = t.Item(Num).outerHTML
else
ExtractTag = t.Item(Num).innerText
end if
End Function


Thanks for all the help, you are the man.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 13, 2006 5:43 pm

I think the issue is that INPUT tags don't have InnerText - that property makes no sense for INPUT tags. You want to query it's VALUE. So try replacing InnerText with Value:

ExtractTag = t.Item(Num).Value

But note therefore that this won't work for other tags - only INPUT tags. You may want to create a different function specific for INPUT tags, or modify it thus:

Code: Select all

Function ExtractTag(TagName,Num,all)
  dim t
  set t = IE.document.getElementsbyTagName(Tagname)
  if TagName = "INPUT" then
    ExtractTag = t.Item(Num).Value
  else
    if all=1 then
      ExtractTag = t.Item(Num).outerHTML
    else
      ExtractTag = t.Item(Num).innerText
    end if
  end if
End Function
Something like that.

Regarding syntax etc. How to use VBSTART/VBEND, VBRun and VBEval is all in the help file and manual. Functions must be evaluated, Subs can be Run. So VBRun for Subroutines, VBEval for functions (or any VBScript expression where you need a result). As for VBScript itself you will find links to Microsoft's documentation here:
http://www.mjtnet.com/resources.htm
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Thu Jul 13, 2006 6:35 pm

Thanks that worked great.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts