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

Asked

Viewed 1,327 times

4

You can, using a programming language, access a web page with login and password data, set the login and password information and "click" the send button, and can enter the site with your credentials?

After this it is possible to browse the site collecting source information, etc.?

I’m using Lua for testing, but I can test with Java as well.

The URL I’m trying to use is https://acad.unoesc.edu.br/academico/login.jsp

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

3 answers

4

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

At first, Selenium is a framework for testing web graphical user interface, but nothing prevents you from using it to automate tasks.

On the blog of Dyego Costa and has 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, the watir is very simple and yummy to use.

  • Thank you, I’ll take a look at this, as soon as possible I give the feedback.

  • @rodrigokiller the orders

  • 1

    as I am testing Lua, I will test http://luaselenium.sourceforge.net/ which seems to be the Selenium client for Lua.

  • @Rodrigokiller cool, I gave a wanted and had not found :-)

2


  • I know these functions and also the Apatchehttpclient library, I’ve used to download images from a site using Java, however, I can not "understand" the operation of setting parameters, for example, JS, and "send" them to the server.

  • @rodrigokiller try to get a better look at this Tutorial This is pure Java, but I really believe that in this case your real doubt is with HTTP protocol in itself. If you can provide more details of your question...

  • What don’t you understand exactly? You want to make a POST to the URL https://acad.unoesc.edu.br/academico/j_security_check (the example of Vogella is already a POST) passing the parameters j_username, j_password and j_uri, in the case of Apachehttpclient the passing of parameters is for example nameValuePairs.add(new BasicNameValuePair("j_username", "fulano")); as Vogella’s blog exemplifies.

  • @Joshua I tried to use Postman, for example, on the page in question, setting the Keys (j_username and j_password). However, I didn’t get a return, or I did something wrong. Anyway, you’re going through various materials, now just sit down and read them. Thank you very much for your answers.

0

If you are on Windows, you can use Autoit a tool that I find quite useful. I usually use to mess with the mouse and keyboard, but it does much more than that.

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

  • I’ll take a look thank you :)

Browser other questions tagged

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