Jump to content
Sign in to follow this  
gandalfthewhite

Can AutoIt verify a web page

Recommended Posts

gandalfthewhite

I am trying to run an autoit script that opens a web page by entering an address on the address bar. (eg: www.yahoo.com)

Can I make sure that the yahoo web page is opened?

If autoit cant do it, is there any other automation tool that might be able to do it?

Share this post


Link to post
Share on other sites
tagada

hi

you can use _IECreate

this, is in the help file :

_IECreate ( [$s_Url = "about:blank" [, $f_tryAttach = 0 [, $f_visible = 1 [, $f_wait = 1 [, $f_takeFocus = -1]]]]] )

$s_Url Optional: specifies the Url to navigate to upon creation

$f_tryAttach Optional: specifies whether to try to attach to an existing window

0 = (Default) do not try to attach

1 = Try to attach to an existing window

$f_visible Optional: specifies whether the browser window will be visible

0 = Browser Window is hidden

1 = (Default) Browser Window is visible

$f_wait Optional: specifies whether to wait for page to load before returning

0 = Return immediately, not waiting for page to load

1 = (Default) Wait for page load to complete before returning

$f_takeFocus Optional: specifies whether to bring the attached window to focus

0 = Bring window into focus

-1 = (Default) do not bring window into focus

Before, you may test if internet connexion exist with

#include <IE.au3>

$testconnexion = InetGetSize("http://www.autoitscript.com/autoit3/files/beta/update.dat") ;this url comes from help file too

if $testconnexion == 0 then
     MsgBox(4096, "Result", "No connexion")
else
     _IECreate ("www.yahoo.com", 1, 1, 0)
endifoÝ÷ Ù.q©í¯+aËh¡«­¢+Ø(¥¹±Õ±Ðí%¹ÔÌÐì((ÀÌØíÕÉ°ôÅÕ½ÐíÝÝܹ塽¼¹½´ÅÕ½Ðì((ÀÌØíÙÈôA¥¹ ÀÌØíÕÉ°°ÈÔÀ¤)¥ÉɽÈôôÄQ¡¸(%5ͽà À°ÅÕ½ÐíMÑÑÕÌÅÕ½Ðì°ÅÕ½Ðí!½ÍХ̽±¥¹ÅÕ½Ðì¤)±Í%ÉɽÈôôÈQ¡¸(%5ͽà À°ÅÕ½ÐíMÑÑÕÌÅÕ½Ðì°ÅÕ½Ðí!½ÍÐ¥Ìչɡ±ÅÕ½Ðì¤)±Í%ÉɽÈôôÌQ¡¸(%5ͽà À°ÅÕ½ÐíMÑÑÕÌÅÕ½Ðì°ÅÕ½Ðí  ÍÑ¥¹Ñ¥½¸ÅÕ½Ðì¤)±Í%ÉɽÈôôÐQ¡¸(%5ͽà À°ÅÕ½ÐíMÑÑÕÌÅÕ½Ðì°ÅÕ½Ðí=Ñ¡ÈÉɽÉ̸¸¸ÅÕ½Ðì¤)±Í(}%
ÉÑ ÀÌØíÕÉ°°Ä°Ä°À¤)¹%
Edited by tagada

Share this post


Link to post
Share on other sites
_Kurt

You might also want to look into _InetGetSource($URL), if you want to compare the source code from a website.

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites
gandalfthewhite

Thanks,

So in short you are saying that I can use the _IECreate() function to open a web-browser and go to a site? right?

Well, I can open that site, but I need to know the correct site opened. I see that the IECreate function returns 0 on success. Would this decide that the correct page opened?

Lets say, instead of www.yahoo.com, I enter "www.abcd12345.com" and now it opens a search page, wouldnt IECreate still return 0?

How would I be able to distinguish between a regular web site being opened as to a seach page being rendered?

Share this post


Link to post
Share on other sites
_Kurt

Although this seems to work fine for me:

#include <IE.au3>
If _IECreate("somesite.com") <> 0 Then MsgBox(0,"","")

You can still distinguish whether the InternetExplorer.Application is at your desired page or not. There are probably multiple ways or doing so, but this is how I would approach it. Using _IEBodyReadHTML, we can retrieve partial source from the webpage, which we can then compare using string functions, or a simple If..EndIf statement.

Also, perhaps you ought to take a look into the _IECreate return values..

@Error: 0 ($_IEStatus_Success) = No Error

1 ($_IEStatus_GeneralError) = General Error

3 ($_IEStatus_InvalidDataType) = Invalid Data Type

4 ($_IEStatus_InvalidObjectType) = Invalid Object Type

6 ($_IEStatus_LoadWaitTimeout) = Load Wait Timeout

8 ($_IEStatus_AccessIsDenied) = Access Is Denied

That's all I can currently think of (I know I'm missing something)

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites
/dev/null

Thanks,

So in short you are saying that I can use the _IECreate() function to open a web-browser and go to a site? right?

Well, I can open that site, but I need to know the correct site opened. I see that the IECreate function returns 0 on success. Would this decide that the correct page opened?

Lets say, instead of www.yahoo.com, I enter "www.abcd12345.com" and now it opens a search page, wouldnt IECreate still return 0?

How would I be able to distinguish between a regular web site being opened as to a seach page being rendered?

did you check the help file for _IECreate()? It requires the URL as a parameter. So, why don't you check the URL before you call _IECreate() if you want to be sure to open the correct URL !??!

$oIE = _IECreate ("www.autoitscript.com")

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
gandalfthewhite

Thanks Kurt,

This is a sample script I have

#include <IE.au3>

$oIE = _IECreate ("www.yahoo.com", 0, 1, 1, 0)

If @error=0 Then

MsgBox(4096, "No Error", "This Site opened")

Else

MsgBox(4096, "Error", "Something Wrong")

EndIf

_IEQuit($oIE)

Though this will work, I think some indepth analysis of the page needs to be done to make sure the correct site is opened.

dev/null the url in the IECreate() is something I would enter in the function. But how can I guarantee that the correct site is opened.

TO give you more details...the script I am working on is for a ISP client.

So I install the client and the client connects to the internet.

Now I open a website with a valid url -> I should get some sort of result that the webpage opened (@error=0 might suffice)

Now I open a webiste with a wierd url (www.abcde12345.com) -> most IEs will direct me to a seach page. How do I know I have been directed to a seach page and not www.<somesite>.com as @error still might return a 0 (point out if this is wrong)

Share this post


Link to post
Share on other sites
/dev/null

Though this will work, I think some indepth analysis of the page needs to be done to make sure the correct site is opened.

dev/null the url in the IECreate() is something I would enter in the function. But how can I guarantee that the correct site is opened.

I'm not sure if I understand the problem.... Do you want to go to a specific web page (www.yahoo.com) or to ANY page? In the first case,

use _IEDocReadHTML() and check the returned HTML text to figure out if it's the correct web page. In the second case, I don't know solve the "problem". Maybe we need more information about what you want to do....

From your topic title: Can AutoIt verify a web page.

What do you mean by verify??

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
_Kurt

He means that he wants to see whether the URL is "valid" or not. I got an idea..

Rather than checking if the $oIE object URL is valid, why don't you _InetGetSource the same URL and see if it fails or not. example:

#include <Inet.au3>
#include <IE.au3>

Local $Link = "www.somestupidsite.com"
$Test = _InetGetSource($Link)
If @error = 1 Then
    Msgbox(0,"","Invalid Link")
Else
    _IECreate($Link)
EndIf

(Untested)

Hope that works,

Kurt

EDIT:

-Forgot my #includes

-Tested example, it works. Try: $Link = "www.google.com". :rolleyes:

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites
gandalfthewhite

ok, i'll take it from the start...

1. verify means...to make sure...lets say I want to open...www.yahoo.com

If I manually do it...I can see that a webpage with some data about yahoo, some news, some finance information is displayed...right? So I know this is a yahoo page. Lets say I try to open www.yahoo.com and I get redirected to a hotmail page (hypothetical situation) I know that I am being directed to a wrong page and hence something is no right.

How do I use automation to verify this behavior. Regardless to say that the content of a page is dynamic so I cannot rely on the page data.

2. Lets say I open www.yahoo.com but I get a 404 page not found, how do I verify this behavior with automation

3. Lets say I enter www.abcdef12345.com (try this link in your web browser), you'd probably be taken to the msn live search with the search string as www.abcdef12345.com (default IE behavior). I can see it and say that it took me to a search page (again could be dynamic). How can I verify this behavior with autoit automation.

Hope these example make it clear...

more details...I am automating test cases for an Internet Service Provider. Lets say you have a computer and its not hooked on to the internet. You use the software and hardware provided by this provider to connect and then browse the internet. When you browse, you open a web page. The test cases is to ensure the

1. correct web page is opened if a valid url is given

2. If there is not connection, or something went wrong a 404 page not found is displayed

3. If a non existing url is opened, it takes you to the seach page.

Let me know if you need any further clarifications.

Share this post


Link to post
Share on other sites
/dev/null

more details...I am automating test cases for an Internet Service Provider. Lets say you have a computer and its not hooked on to the internet. You use the software and hardware provided by this provider to connect and then browse the internet. When you browse, you open a web page. The test cases is to ensure the

1. correct web page is opened if a valid url is given

2. If there is not connection, or something went wrong a 404 page not found is displayed

3. If a non existing url is opened, it takes you to the seach page.

Let me know if you need any further clarifications.

O.K. then use ObjEvent() to figure out if something went wrong.

$oIE=ObjCreate("InternetExplorer.Application.1")       
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")

$oIE.Visible=1
$oIE.RegisterAsDropTarget = 1
$oIE.RegisterAsBrowser = 1
$oIE.Navigate( "http://www.AutoItScript.cim/" )

sleep(5000)

$SinkObject=0           
$oIE.Quit           
$oIE=0
exit

Func IEEvent_NavigateError($pdisp, $url, $tf, $status,$cancel)
        $msg = "Problems loading page: " & $url & @CRLF
        $msg = $msg & "Status: " & $status & @CRLF
        MsgBox(0,"PROBLEMS",$msg)
EndFunc

Here is a list of possible error codes: http://msdn2.microsoft.com/en-us/library/bb268233.aspx

Hope that helps. If not, I cannot help, as I can't tell you how to detect if the content returned "really" belongs to the URL you used, as this would involve some clairvoyant skills, which are not yet implemented in AutoIT ;-)


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
DaleHohm

Look at _IEPropertyGet with "locationurl"

_IECreate cannot give you the error status you want because the .Navigate used has no return value.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
Richard Robertson

Curse you Dave, and your knowledge of your own UDF. I was seeing all these responses and hoping to answer this.

Share this post


Link to post
Share on other sites
/dev/null

update. use ie.au3.

#include <ie.au3>

$glb_IE_Error = 0

$oIE = _IECreate()
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")

; Now retrieve the page
_IENavigate($oIE,"www.autoitscript.cim")

if $glb_IE_Error then
    MsgBox(0,"",$glb_IE_Error)
endif

Func IEEvent_NavigateError($pdisp, $url, $tf, $status,$cancel)
        $msg = "Problems loading page: " & $url & @CRLF
        $msg = $msg & "Status: " & $status & @CRLF
        $glb_IE_Error = $msg
EndFunc

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites
DaleHohm

Good idea... I don't usually think of this approach because it is not practical for me to generalize a solution like this in IE.au3.

To make this a little cleaner, I think I would declare $gbl_IE_Error as GLOBAL to avoid scope confusion for readers.

Dale

update. use ie.au3.

#include <ie.au3>

$glb_IE_Error = 0

$oIE = _IECreate()
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")

; Now retrieve the page
_IENavigate($oIE,"www.autoitscript.cim")

if $glb_IE_Error then
    MsgBox(0,"",$glb_IE_Error)
endif

Func IEEvent_NavigateError($pdisp, $url, $tf, $status,$cancel)
        $msg = "Problems loading page: " & $url & @CRLF
        $msg = $msg & "Status: " & $status & @CRLF
        $glb_IE_Error = $msg
EndFunc

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
gandalfthewhite

/dev/null & Dale,

This might be THE answer to my problem.

I tested this with a valid URL and also when there was no internet connection and it worked.

However, lets try this case...an invalid url

1. (Manually)

Open IE and type in www.qwertzxcvb.com and you would see a live msn search or maybe a google search or some other search based on your IE toolbar.

2. Substitute the same url in the script. The web page opens and says it cannot be displayed and shows the error message dialog box. Why? Shouldnt this work as IE would work and not be an error?

3. Another classic example would be if I type "barnesandnoble" in IE, it will take me to the barnes and noble website.

But if I replace the whole url with "barnesandnoble" -> [_IENavigate($oIE,"barnesandnoble")] it again says page cannot be displayed and shows the error message.

Somehow it seems that this is not replicating the IE behavior exactly.

Share this post


Link to post
Share on other sites
DaleHohm

As you point out, your toolbar is a layer on top of the normal browser operation, so it should not be surprising that it produces different behaviour compared to low-level operations in the DOM.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
gandalfthewhite

I agree that the behavior will be based on the top layer toolbar.

So let me back up here. Lets say I have no toolbar installed, then the basic IE will take me to the msn seach page with the text entered in the url as the search string.

Do you think I can grab the resolved url (search site url) and parse that string to figure out if a seach site was reached?

If so, what would be the function to grab a url from the current E thats open?

Thanks

Share this post


Link to post
Share on other sites
DaleHohm

_IEPropertyGet($oIE, "locationurl")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×