Try to get WatiN for links / browsers

I recently started testing and using WatiN, and I ran into some problems / errors that I really cannot solve.

At first I described poorly what I was doing with my trials. I will go and get all the links in a particular div in the list ... so I have lists of links ... that I'm going to go through ... In a loop, you will use the link.clicknowait () function to open that link (it opens on a new tab ie). Then I sleep the thread for a few seconds, and I close this browser by attaching this link (url) to the new browser, and after that the browser closes, since im always uses it using the using (..) statement.

So, the first problem is that when the browser receives all the links and starts clicking on them, one of the links may lead to the wrong page, which means that it can lead to the page that says the doenst page exists more , so after that I can’t close this page anymore ... how to solve this problem and attack, that is, this non-existing page? It does not have a fixed url ... anything you can recommend?

Is there something like "Try attach to ...." because otherwise I get an error message if it tries to attack the browser with a link that does not exist.

There is also in any case, to check whether the link in the list of links is really correct, because I also had several times, because it could not click on this link, because it was empty on the page ... Or I can check that something like link.trytoclick () and if the error just ignores this link and goes further ???

And the last question, having clicked a lot of links and opening and closing the browser, got an outofmemoryexception error .. how could it be, I used the 'using statement', which always closed the browser when it was out of it ...

Thanks in advance for your help.

+4
source share
1 answer

You can use href to open the link in the same window of the browsing session, after checking the link, which you can return to the original page.

Something like that:

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 a link exists:

  session.browser.Back(); 
+1
source

Source: https://habr.com/ru/post/1385057/


All Articles