Put information in field fields of a URL and send it to the server with a program language

4

It is possible, using a programming language, to access a web page with login and password data, to set login and password information and to "click" the submit button, and can enter the site with your credentials?

After this you can browse the site collecting source information, etc.?

I'm using Moon for testing, but I can test with Java as well.

The URL I'm trying to use is link

On Lua, I get source code and status, etc., with luasocket(http) .

    
asked by anonymous 12.02.2014 / 19:26

3 answers

2

Friend HttpURLConnection is a good way to start, but for practical purposes I advise you to take a look at this Vogella blog: link

There is an example of a POST request for a login page, using Apache HttpClient.

Hugs

    
12.02.2014 / 19:35
4

Using Java you can use the selenium framework. After writing a script, it opens the browser and "has a life of its own".

In principle, selenium is a framework for testing web GUI, but nothing prevents you from using it to automate tasks.

In the blog Dyego Costa and have the following example of how to use selenium, to get an idea of how easy it is. In the example he does a google search:

[TestMethod]
public void MeuTesteSuperMassaSoQueNao()
{
    // Usando o firefox
    IWebDriver driver = new FirefoxDriver();

    // acessa a página do google
    driver.Navigate().GoToUrl("http://www.google.com/");

    // Vai no campo de busca, escreve "Cheese" e aperta enter          
    IWebElement query = driver.FindElement(By.Name("q"));
    query.SendKeys("Cheese");
    query.Submit();

    // Configura um timeout
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

    // Espera até o título da página tiver cheese, tá pronto (ou o timeout acontencer)
    wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });

    // Essa parte é o teste - pode ignorar, já que tu não quer testar nada
    driver.Title.Should().Contain("cheese");

    // fecha o browser
    driver.Quit();
}

If you prefer ruby, watir is very simple and nice to use.

    
12.02.2014 / 19:30
0

If you're on Windows, you can use AutoIt a tool that I find quite useful. I usually use it to tinker with the mouse and the keyboard, but it does much more.

Below I got a code to enter the page and log in.

#include <ie.au3>
$oIE = _IECreate ("http://yoursitename.com")
$oForm = _IEFormGetObjByName ($oIE, "form id or name")
$oQuery1 = _IEFormElementGetObjByName ($oForm, "uname textfield id or name")
$oQuery2 = _IEFormElementGetObjByName ($oForm, "pwd text field id or name")
$uname="Yourusername"
$pwd="yourpassword"
_IEFormElementSetValue ($oQuery1,$uname)
_IEFormElementSetValue ($oQuery2,$pwd)
$oButton=_IEGetObjById($oIE,"")
_IEAction ($oButton, "click")
_IELoadWait($oIE,0)

source

    
12.02.2014 / 22:16