Please Help - how do I handle redirects?

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.

Moderators: Marcia, iOpus, Hannes, iOpus, Tech Support, Tom, iOpus

Please Help - how do I handle redirects?

Postby MAtkins on Mon Jun 21, 2010 11:00 pm

Hi:

I posted this before but think maybe it wasn't clear that I was hoping for an answer.
So far, every problem I've had with iMacros has been pretty readily solvable - until now.
Generally, the program is really powerful but I'm at a road block.

My app. is in php and depends entirely on its ability to read the html from the last loaded page.
A standard login is: 1. Login, 2. Get 'You are logged in . . . ' which after 2 seconds or so, 3. redirect to the main 'logged in' page.

iMacros keeps reading the page before the redirect, which makes sense unless I can tell it 'wait for the redirect to complete'.
I tried using WAIT but iMacros executes the macro after the wait even if it's right in the middle of downloading the page. I tried to add a WAIT SECONDS=#DOWNLOAD# but then it makes me wait a full 60 seconds for nothing.

How should I handle a delayed redirect to be able to read the html and execute the remainder of the macro on the redirected page? :?: :!:
MAtkins
 
Posts: 25
Joined: Thu Jun 03, 2010 12:28 pm

Re: Please Help - how do I handle redirects?

Postby Tom, iOpus on Tue Jul 13, 2010 8:21 am

Matkins,

The redirect should be handled automatically by iMacros. For example, I ran the following macro in iMacros for Firefox, iMacros 7 and iMacros 6.9 and they all waited for the redirected page to load and then clicked the link accordingly. Try it for yourself.

Code: Select all
TAB T=1
URL GOTO=http://www.davmagic.com/PAGES67.html
TAG POS=2 TYPE=A ATTR=TXT:GO<SP>UP<SP>TO<SP>MENU
Regards,

Tom, iOpus Support
Tom, iOpus
 
Posts: 445
Joined: Mon May 31, 2010 9:59 am

Re: Please Help - how do I handle redirects?

Postby MAtkins on Wed Jul 14, 2010 12:59 am

Thanks for the reply.

I'm running into situations where the redirect is delayed.
In some cases they're using a META tag to 'refresh' after 2 seconds.

A classic example is a login where you see a page 'YOU ARE NOW LOGGED IN' for about 3 seconds then you're redirected to the main page.
iMacros is reading the HTML from the page before the redirect. I need it to read the page after the redirect.

I tried Go and then WAIT but the WAIT overrides the second page download and starts the macro right in the middle of the download.

I found somewhat of a work around (I think) for cases where the META tag refresh exists.
I just read the URL attribute and then tell iMacros to GO to that URL.
We'll see how that works.

If you've got a better suggestion I sure would appreciate it.
MAtkins
 
Posts: 25
Joined: Thu Jun 03, 2010 12:28 pm

Re: Please Help - how do I handle redirects?

Postby Tom, iOpus on Wed Jul 14, 2010 10:34 am

Did you try the sample macro I posted? That web page uses a META tag to refresh after 5 seconds, but iMacros still waits for the redirect to load before clicking the link.
Regards,

Tom, iOpus Support
Tom, iOpus
 
Posts: 445
Joined: Mon May 31, 2010 9:59 am

Re: Please Help - how do I handle redirects?

Postby MAtkins on Thu Jul 15, 2010 12:33 am

Thanks again for working this out with me.

Yes, I see that it waits for the next click.
I tested it on one of the sites that I'm having trouble with and it worked fine.

It turns out that the problem is, though it will wait before clicking a link, it doesn't wait before retrieving the HTML.

The following code will return the HTML in the redirect page, not the final redirected page.
Is there any way I can get it to wait for the redirect to finish before it retrieves the HTML?

Code: Select all
iMacros.App oIMacros = new iMacros.App();            
oIMacros.iimInit ("", false, null, null,null, 600);            
string sCode = "CODE:CLEAR\r\n";
sCode += "URL GOTO=http://www.iopus.com/imacros/home/?a=1351003&v=6900210\r\n";
sCode += "URL GOTO=http://z3.invisionfree.com/HolySpirit/index.php?\r\n";   
sCode += "TAG POS=1 TYPE=A ATTR=TXT:Log<SP>In\r\n";         
sCode += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:LOGIN ATTR=NAME:UserName CONTENT=Tester\r\n";
sCode += "TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:LOGIN ATTR=NAME:PassWord CONTENT=test123\r\n";
sCode += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:LOGIN ATTR=NAME:submit\r\n";
sCode += "TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTML";
oIMacros.iimPlay(sCode, 600);
string sHTML = oIMacros.iimGetLastExtract(0);
MAtkins
 
Posts: 25
Joined: Thu Jun 03, 2010 12:28 pm

Re: Please Help - how do I handle redirects?

Postby Tom, iOpus on Thu Jul 15, 2010 2:47 am

I see, sorry for the misunderstanding. How about adding a TAG command for an element on the redirected page so that iMacros waits for this element first before the TAG command to extract the HTML? Something like this:

Code: Select all
...
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:LOGIN ATTR=NAME:submit
TAG POS=1 TYPE=STRONG ATTR=TXT:Logged<SP>in<SP>as:<SP>Tester
TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTML
...
Regards,

Tom, iOpus Support
Tom, iOpus
 
Posts: 445
Joined: Mon May 31, 2010 9:59 am

Re: Please Help - how do I handle redirects?

Postby MAtkins on Sat Jul 17, 2010 12:21 pm

Well, it works pretty well but still too limited.

The problem is, the sites use different text in the tags.
Sometimes they're not even in English or even use the English alphabet.

The HTML however is consistent and therefore dependable.

If I could find a way to make it wait based on something like:
TAG POS=1 TYPE=A ATTR=HREF:*usercp.php
this it would work for me.
This code crashes the browser.

I tried to solve it by creating a DoSleep loop that waited for the certain HTML to show up 'usercp.php'.
I learned that
TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTML
will read the HTML right in the middle of a download.
So, it found that text before the page had fully loaded.

Can you think of any other ways to do this?
Or is there any way I can do something like:
TAG POS=1 TYPE=A ATTR=HREF:*usercp.php
MAtkins
 
Posts: 25
Joined: Thu Jun 03, 2010 12:28 pm

Re: Please Help - how do I handle redirects?

Postby Tom, iOpus on Wed Jul 21, 2010 7:06 am

I don't know why TAG POS=1 TYPE=A ATTR=HREF:*usercp.php is crashing your browser. I tried this line and it didn't crash the browser, but it also didn't find the element (a search through the source HTML revealed no occurrences of usercp.php). So I changed it to the following and it worked:

Code: Select all
TAG POS=1 TYPE=A ATTR=HREF:*UserCP* EXTRACT=HREF
SET !EXTRACT NULL

Notice that I had to use an EXTRACT here to prevent iMacros from clicking the link, and then I clear the extraction buffer in the next line. The following also works to find the user name link just after "Logged in as:":

Code: Select all
TAG POS=1 TYPE=A ATTR=HREF:*index.php?showuser* EXTRACT=HREF
SET !EXTRACT NULL

I am testing all of this using the iMacros 7 Browser.
Regards,

Tom, iOpus Support
Tom, iOpus
 
Posts: 445
Joined: Mon May 31, 2010 9:59 am

Re: Please Help - how do I handle redirects?

Postby MAtkins on Wed Jul 28, 2010 4:42 am

OK, thanks I'll try this.
MAtkins
 
Posts: 25
Joined: Thu Jun 03, 2010 12:28 pm


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 1 guest