X-Scripts

READY-MADE SOLUTIONS FOR YOUR BUSINESS

OUR CONTACTS:
Skype: igor_sev2
Email : order@x-scripts.com

How to write a simple script will AutoFill the web form on Human Emulator

Very often on the Internet we found the forms on web pages. These forms on web pages serve for the supply of the questionnaires, the filing of declarations, filing of various applications, send comments and much more. It happens so often that we regularly have to fill out the same form on the same or on different sites, for example: Postings on various Internet boards. This process becomes routine and we want to get rid of it. To do this you just need a program that will do it for You - say the program for auto classifieds, or program to AutoFill forms or AutoFill documents, etc. Actually, all you need is a program Human Emulator, since she does all the steps listed above. Besides Human Emulator fills web forms of any complexity, written including and with usage of ajax and javascript-s, knows how to handle captcha and a lot more then able to do useful things, that is useful in solving tasks such as filling in web forms or the classifieds.

In this article we will tell you how to write a simple script to auto-fill forms with Human Emulator on the example of submission ads on the Board avito (avito.ru).

To begin, create a new script and add code to go to the desired website, in this case, the Bulletin Board avito(avito.ru):

$browser->navigate("http://www.avito.ru/");

Then go to the form filling ad. To do this, click on the link with the text "place an ad":

$anchor->click_by_inner_text("advertise",false);

We now proceed to complete the form. For naganori we choose "campaign" because this way is a bit more complicated and we have to fill out more fields. Right-click context menu of the checkbox and by the name set the focus to it. After that we use the emulate function keys and after you set the focus to the checkbox emulates pressing the Right(Right):

$keyboard->send_key(39);

note: View of the keyboard codes that are used in functions send_key you can see using menu "Tools->View keyboard codes" Humana Emulator or by pressing Ctrl+Shift+K. In the dialog that opens, press the key for us and look at its code.

Next to text fields via context menu for each field and selecting "edit item->set_value_by_name" add to the script following code:

// campaign
$input->set_value_by_name("seller_name","name");

// face
$input->set_value_by_name("manager","person");

// mail
$input->set_value_by_name("email","mail");

// phone
$input->set_value_by_name("phone","1234567890");

If you need to do click on the checkbox "I Agree" on behalf of the checkbox:

// checkbox - agree
$checkbox->click_by_name("allow_mails");

Further make a choice of the city. If any element does not react well to work with him even through the attributes, we can always use emulation of the keyboard. When we were writing the script there were difficulties when working with the element of choice in the city. So just after entering the phone will emulate a keystroke "tab", then clicked, focus is switched to the selection item of the cities. Then, after opening the list of cities, press "space" - it is a Gap. Now select the town itself. Here it is possible through the emulation of pressing the 1st letter of the city or through need number emulate pressing the "down". If you don't see the city, go to the tab "choose another city" - emulates double-clicking the letters "B", but in this case do not forget Russian layout or use humana to switch language:

$keyboard->set_current_language("EN");

Selecting a city, then the analog keys through emulation fill in the rest

// city
$keyboard->set_current_language("EN");
$keyboard->send_key(9);
sleep(2);

// Volgograd
$keyboard->send_key(68,true);
sleep(2);

// Voroshilovskiy district
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(68,true);
sleep(2);

// 
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(82,true);
sleep(2);

// buy (emulation "to")
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(82,true);
sleep(2);

// number of rooms
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(50,true);
sleep(2);

For a description and other fields do the same as with the previous fields - work via context menu for each field of the "edit item->set_value_by_name".

// description
$textarea>set_value_by_name("description","description");

// 
$input->set_value_by_name("price","1234");

Publish our advert by clicking "place an ad", which is actually a link:

// published
$anchor->click_by_inner_text("advertise",false);

So between all the steps to add a pause to the page with the web form time to respond to our actions:

// pause between steps 
sleep(2);

In the end we must create the following script:

<?php

$xhe_host ="127.0.0.1:7010";

// The following code is required to properly run XWeb Human Emulator
require("../../Templates/xweb_human_emulator.php");

// go to the site
$browser->navigate("http://www.avito.ru/");
sleep(2);

// perehodim to the form filling
$anchor->click_by_inner_text("advertise",false);
sleep(2);

// start filling
$radiobox->set_focus_by_name("private");
$keyboard->send_key(39);

// campaign
$input->set_value_by_name("seller_name","name");

// face
$input->set_value_by_name("manager","person");

// soap
$input->set_value_by_name("email","mail");

// checkbox - agree
$checkbox->click_by_name("allow_mails");

// phone
$input->set_value_by_name("phone","1234567890");

// city
$keyboard->set_current_language("EN");
$keyboard->send_key(9);
sleep(2);

// Volgograd
$keyboard->send_key(68,true);
sleep(2);

// Voroshilovskiy district
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(68,true);
sleep(2);

// 
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(82,true);
sleep(2);

// buy (emulation "to")
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(82,true);
sleep(2);

// number of rooms
$keyboard->send_key(9,true);
sleep(2);
$keyboard->send_key(50,true);
sleep(2);

// description
$textarea->set_value_by_name("description","description");

// 
$input->set_value_by_name("price","1234");
sleep(2);

// place an ad
$anchor->click_by_inner_text("advertise",false);

// Quit
$app->quit();
?>

Similarly, the script is written all the scripts AutoFill web forms, auto classifieds, dobavlenie comments, etc.

Among our scripts for Human Emulator you can easily find more examples that solve similar tasks.



<< Other articles