Alnedru
Alnedru

Reputation: 2655

Try to get for WatiN for links/browsers

I've recently started to test and use WatiN, and i came across some of problems/errors that i cant really solve.

First ill describe what i'm doing with my tests .. I'll go and get all the links in a specific div in a list ... so i have a link lists ... which im gonna loop thru ... In the loop im gonna use a link.clicknowait() function, to open that link (it opens in a new ie tab) .. then i sleep thread for like few seconds and i close that browser by attaching that link (url) to a new browser and after that the browser is closed as im using it always with 'using (..)' statement.

So the first problem is that when the browser gets all the links and start to click them one of the links might lead not the right page, meaning like it can lead to a page that is saying page doenst exist anymore, so after that i cant close that page anymore ... how to solve this and attack ie to that not existing page? It hasnt got fixed url ... anything that you can recommend?

Is there a method something like "Try attach to ...." because else i get an error if it tries to attack a browser to a link which doesnt exist.

Also is there anyway to check if the link in a links list is still the right one, cuz i also had an exeption few times that it couldnt click on that link because it was empty in the page ... Or can i check something like link.trytoclick() and if an error and just ignores that link and goes further ???

And the last question after clicking alot of links and opening and closing browser i got an error outofmemoryexception .. how can it be, i've used 'using statement' which always closed browser when it was out of it ...

Thanks in advance for the help.

Upvotes: 4

Views: 1605

Answers (1)

alonp
alonp

Reputation: 1337

You can use the href to open the link in the same window of your watin session, after you verify the link you can go back to original page.

Some thing like this:

string href = browser.Link("link_id").GetAttributeValue("href"); //or your link from the collection
browser.GoTo(href);
//Perform you check
browser.Back();

To check if the link exists use:

  session.browser.Back();

Upvotes: 1

Related Questions