The current manual process is as follows:

  1. You need to go to the browser and open a special link;

  2. You need to choose your login from the drop-down list;

  3. Select the folder with the files and the files themselves that will be downloaded;

  4. Further, for each window, forms for filling appear, for example: the first file is called Автор - Книга.doc , under this name there are two forms for filling: "Author:"; "Book";

  5. Hands are copied "Author" in the form to fill out; hands are copied "Book" in the form to fill in - so for each individual downloadable file;

  6. After all the forms with "Authors" and "Books" are filled in, the "Load" button is pressed;

  7. According to the download results, the "Download Complete" window appears: "Author - Book" .... and this information should be copied, for example, into an Excel file.

Question: Is it possible to write a program that automates this process - so that it fills out forms according to a standardized title (between the author and the book, there can always be a space, a hyphen, a space); to copy and enter information into an Excel file; to transfer downloaded files from one folder to another.

From programming skills VBA excel only. I also want to understand what exactly and in what programming languages ​​should be studied in order to be able to make such a program. Preferably in Python. And I would be very grateful for the answers to how to solve successive pieces of this satisfied big task and where you can read the answers so that these pieces work: how to fill out forms in the browser using the file name “Author - Book.doc” on these forms? How to choose a login from the list? and etc.

  • UI Automation can handle it. C #. ru.stackoverflow.com/a/509694/10105 - VladD
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky
  • There are many software testing automation systems. They are not very common in the world due to the fact that they are specific to the QA-engineer profession, but they cope with such tasks on time. There are systems that work better with the web, with mobile, with the desktop. Examples - Uppium, Selenium - Eugene Bartosh

2 answers 2

Instead of trying to repeat the user's actions with the GUI literally, you can look at the task through the eyes of a programmer:

  • instead of opening the browser, filling out and submitting the form, you can execute an http POST request directly ( request.post() )
  • instead of selecting files in the graphical dialog, you can use the API, which returns a list of files by pattern ( Path().glob("*.doc") )
  • instead of copying the book’s metadata from the name of the file Author - Title.doc into the form elements, the required request parameters are set directly (author, title in the example). The metadata itself from the file name can be obtained by manipulating the string with the name directly: fn.split('-') or using regular expressions: r'^([^-]+?)\s*-\s*(.+)\.doc$'
  • instead of copying download results from windows to Excel, the server’s response is printed directly in csv format to standard output ( csv.writer(sys.stdout) ). What is easy to copy to file ( | tee -a books.csv )

The final script that loads files with books might look like this:

 #!/usr/bin/env python3 '''Upload "<author> - <title>.doc" books from the given directory. Usage: upload-books <dir-path> | tee -a books.csv ''' import csv import re import sys from pathlib import Path import requests # $ pip install requests if len(sys.argv) < 2: sys.exit(__doc__) src_dir = sys.argv[1] with requests.Session() as sess: writer = csv.writer(sys.stdout) for path in Path(src_dir).glob('*.doc'): # for each book metadata = re.findall(r'^([^-]+?)\s*-\s*(.+)\.doc$', path.name) if not metadata: print("warning: can't find author, title in path:", path, file=sys.stderr) continue # don't upload # upload book author, title = metadata[0] book = {path.name: (path.name, path.open('rb'), 'application/msword'), 'author': author, 'title': title} r = sess.post('https://example.com/api/v1/books', files=book, auth=('user', 'passwd')) if not r.ok: print("warning: can't upload book from path:", path, file=sys.stderr) continue # don't save book info # save uploaded book info data = r.json()['response'] writer.writerow([str(path), author, title, data['url']]) 

This is a good case when the site has an explicit API or a spontaneously generated set of http requests / responses, does not require the execution of dynamic code in the browser (or when the results of this execution can be easily modeled).

In a less successful case, when, for example, books are answered by the Silverlight control, which uses some of its own protocol to communicate with the server, it may be easier to use GUI automation tools such as pywinauto, pyautogui, or AutoIt (mentioned in response to a similar question on stack overflow) .

In the intermediate case, the interface is implemented in a javascript browser and can be automated using it, using something like Selenium WebDriver (+ headless chrome ).

    The most common tool for such purposes is curl . For example, for a form with the fields name, age and town, the command should be like this:

     curl -d Name="HarryP" -d Age="123" -d Town="DefaultCity" -d Form_Submit="Send" http://www.example.com/process-form.php