How to click a button on a website? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- formulator · 2020-05-06 03:35 Good morning friends, I have a button on a website with this data:       I would like to make a code to click this button,    through my program button. Thanks. ---------------------------------------------------------------------- devEric69 · 2020-05-06 14:51 Hello, As a prerequisite to do what you want, you must first amo be interested in 2 fields of knowledge: 1°) the grammar of the HTML language; in particular, you must understand the 3 concepts which are: • what is HTTP method ("get" and "post", at least), • what is an "action" called on the HTTP server through one of the preceeding methods, • and too, the concept to "SUBMIT" an HTML FORM, if the button submits the data \ values encoded in the controls of the FORM (Cf. https://www.w3schools.com/TAGS/att_button_formmethod.asp for example). 2°) then, the technique that allows to emulate a user click of an already existing button (whatever its encoded action is behind) from a client program written in Object Pascal is called cURL  (Cf. https://forum.lazarus.freepascal.org/index.php?topic=16505.0) Best regards. ---------------------------------------------------------------------- egsuh · 2020-05-07 01:58 You should study javascript. First you can add event handlers for your buttons, like and define function signin(), like ---------------------------------------------------------------------- formulator · 2020-05-07 20:31 devEric69 Thanks for your time and your tips. I've tried to study and learn these codes, but I couldn't move forward. I'm the type of programming student who needs an example functionalizable to be able to create something similar. Trying to understand these lessons without practical examples is like hitting the head of the wall. Grateful friend, I will save the links to study these codes again one of these days. egsuh Thank you friend, but I have no idea how put a javascript code to run inside my Object Pascal code. Thankful. ---------------------------------------------------------------------- lucamar · 2020-05-08 02:54 If you want to do the equivalent from inside a Pascal program, you should ask the user for (or otherwise get) the same information the HTML page asks for and then use any of the networking libs to execute a GET or POST request to the server. That is what the browser does when you click that button. It's not too dificult and IIRC there are several examples of similar things both in this forum and in the wiki. ---------------------------------------------------------------------- zamronypj · 2020-05-08 06:09 Quote from: formulator on May 06, 2020, 05:35:31 amGood morning friends, I have a button on a website with this data:        I would like to make a code to click this button,    through my program button. Thanks. To automate click a button from a website can be done with Free Pascal and headless browser( browser without GUI and have capability to be programmed). Chrome has support for headless mode. However it is not trivial if you need to use Free Pascal. You need to have knowledge on socket programming and also chrome devtools protocol https://chromedevtools.github.io/devtools-protocol/ If you need to build something ASAP, use puppeteer. It is Node.js library to simplify working with chrome headless browser, Code: Javascript  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const puppeteer = require('puppeteer');const browser = await puppeteer.launch();const page = await browser.newPage();await page.goto('http://example.com');page.click('button.header__logged-out- log-in-link'); ---------------------------------------------------------------------- fpcoder · 2020-05-08 09:33 Firefox can also run headless (invisible). I have used a Python script within a Lazarus application to do whats asked about here. ---------------------------------------------------------------------- formulator · 2020-05-09 14:58 lucamar Thank you for the tips. zamronypj It really isn't anything trivial. Thanks, with each new tip I get closer. Amazing how complicated it is to access a simple button. kapibara Good to know, It would be nice if you post an example of how to call the python code from within Lazarus. Thank you. ---------------------------------------------------------------------- fpcoder · 2020-05-09 15:50 It's a while since I worked with this so I dont remember all details. It worked very well though, but you have to invest some time in reading links and try demos until you understand how it is done. Then Python within Lazarus can do basically everything as if the computer user was doing it himself. At first I called my python script using a TProcess. But there is an easier way, the Python4Lazarus component. https://wiki.freepascal.org/Using_Python_in_Lazarus_on_Windows/Linux https://forum.lazarus.freepascal.org/index.php/topic,43557.msg305118.h tml#msg305118 There is also a Python4Delphi stating compatibility with Lazarus. https://github.com/pyscripter/python4delphi ---------------------------------------------------------------------- zamronypj · 2020-05-09 15:51 Quote from: formulator on May 09, 2020, 04:58:01 pmlucamar Thank you for the tips. zamronypj It really isn't anything trivial. Thanks, with each new tip I get closer. Amazing how complicated it is to access a simple button. kapibara Good to know, It would be nice if you post an example of how to call the python code from within Lazarus. Thank you. you can create javascript/python script, call Node.js/python using TProcess and passing relevant script file ---------------------------------------------------------------------- formulator · 2020-05-11 19:51 kapibara  Certo, obrigado pelas dicas, sigo pesquisando e procurando encontrar exemplos práticos.  zamronypj  Ok, grato pelas dicas. Sigo caminhando. Preciso encontrar exemplos práticos.  Cada vez, vocês me dão mais dicas e eu me aproximo mais do código correto.  Obrigado.