Automato for navigation in a Webforms application

Asked

Viewed 2,905 times

3

Guys, it wasn’t the first time or the last time I had to implement an automatic routine that accesses a website or system created on the Webforms platform to capture information.

It has been extremely costly to be able to do any form of automation for capture and automatic navigation in this type of web application only with Webrequests(C#) and/or Webclient (C#).

Note that here I am totally disregarding the possibility of using an Internetexplorer.Application since I do not intend to use interface dependent objects to run (run on servers, services, etc)

Is there any more practical way that I’m not glimpsing ?

  • It’s not in the requested languages, but for almost everything I need, I make http requests normally, simulating browser headers and storing cookies in variables. It has worked very well, including for sites that use ajax and similar (the secret is to look at the entry points of Apis). To extract the data from the pages I created a simple function Extract( &sourcedapagina, stringinicial, stringfinal ) - if I pass the page by reference, the extracted some of the string, good to extract repetitive data. It’s brute force, but it’s fast and light.

2 answers

3


You can also use the Selenium with the Selenium Toolkit for . NET.

Just like Phantomjs, cited by Miguel Angelo, is a browser automation tool. From their homepage

EN:

Selenium Automates browsers. That’s it! What you do with that power is entirely up to you.

PT:

Selenium automates browsers. That’s it! What you do with this power is completely on your own.

Follow a link with the most commonly used commands: http://docs.seleniumhq.org/docs/02_selenium_ide.jspcommonly-used-Selenium-Commands

An example of its use, taken from the international OS: https://stackoverflow.com/questions/6187863/sample-tutorial-of-using-selenium-2-0-web-driver-in-net

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;

class GoogleSuggest
{
    static void Main(string[] args)
    {
        IWebDriver driver = new FirefoxDriver();

        //Notice navigation is slightly different than the Java version
        //This is because 'get' is a keyword in C#
        driver.Navigate().GoToUrl("http://www.google.com/");
        IWebElement query = driver.FindElement(By.Name("q"));
        query.SendKeys("Cheese");
        System.Console.WriteLine("Page title is: " + driver.Title);
        driver.Quit();
    }
}
  • +1 The Selenium is really cool, I’ve used it before, but never on a production scale. He used it to perform interface tests within the company, as he is able to control multiple browsers, and in this context this is an advantage. One drawback is that it requires installing the browser separately.

2

Use the Phantomjs

You can use the Phantomjs to simulate a browser, and do almost everything with it:

  • take screenshots

  • convert page to PDF

  • navigation automation

  • website testing

The project uses Webkit code, and allows doing various things using javascript scripts. No browser required to be installed.

To use on C#

Just include the nuget Phantomjs package:

PM> Install-Package PhantomJS

I know it’s not native to C#, but does it really matter. It’s possible to build real robots with it. Including robots operating in a production environment.

  • in fact I did not know this project, it seems to be an interesting output to use a headless browser. I will wait for others to present more possible solutions!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.