This library was inspired by Selenium and Puppeteer
TSWebDriver4Delphi is a project that encapsulates a variety of tools enabling web browser automation (for now, only Chrome). It specifically provides an infrastructure for the W3C WebDriver specification. With an approach similar to Selenium, TSWebDriver4Delphi allows the automation of interactions with user interface elements, making tests more efficient and reliable.
WebDriver is a remote control interface that enables introspection and control of user agents. It provides a platform- and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers.
Provided is a set of interfaces to discover and manipulate DOM elements in web documents and to control the behavior of a user agent. It is primarily intended to allow web authors to write tests that automate a user agent from a separate controlling process, but may also be used in such a way as to allow in-browser scripts to control a — possibly separate — browser.
The conception of this project originated from the need to perform "Web scraping" on a specific website. Although there are numerous options for this task, such as Selenium with Python, Puppeteer in Node.JS, and Playwright in C#, the question arose: what about Delphi? I chose not to resort to the renowned CEF4Delphi, seeking a lighter alternative with fewer dependencies. I wanted a solution that efficiently addressed the demands, providing a more agile and uncomplicated experience. In this scenario, I developed this tool in Delphi to simplify my work.
⚠️ Attention: The project is still in the alpha stage. Classes and methods may undergo changes during development.
Clone the repository and ensure that dependencies are up to date
git clone git@github.com:GabrielTrigo/TSWebDriver4Delphi.git
git submodule init
git submodule update
Visit the official download page of your browser's WebDriver (currently, only for Chrome) and download the driver that corresponds to the version installed on your computer.
To find your Chrome browser version, follow these steps: go to Settings > Help > About Google Chrome. For instance, the version might be something like 121.0.6167.140 (Official Build) 64-bit. Make sure to download the WebDriver that matches this specific version to ensure proper integration with your development environment.
var
FDriver: ITSWebDriverBase;
FChromeDriver: ITSWebDriverBrowser;
begin
FDriver := TTSWebDriver.New.Driver();
FDriver.Options.DriverPath('your-path\webdriver.exe');
FChromeDriver := FDriver.Browser().Chrome();
end;
📌 See the example project (\example\ExampleTSWebDriver
) and the test project (\test\TSWebDriver4DelphiTests
)
FChromeDriver.NavigateTo('https://letcode.in/elements');
FChromeDriver.WaitForPageReady();
LElement := FChromeDriver.FindElement(FBy.ClassName('search-box__input'));
LElement.SendKeys('automate');
FChromeDriver.WaitForSelector('.search-box__link');
LElement := FChromeDriver.FindElement(FBy.ClassName('search-box__link'));
LElement.Click();
- Official WebDriver documentation W3C
- ChromeDriver docs and download
- Selenium documentation
- W3C WebDriver Spec
![drawing](https://private-user-images.githubusercontent.com/43503837/264857508-bcc0d718-92e2-4107-a074-7f4fcd89c712.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc3NjI2ODYsIm5iZiI6MTcxNzc2MjM4NiwicGF0aCI6Ii80MzUwMzgzNy8yNjQ4NTc1MDgtYmNjMGQ3MTgtOTJlMi00MTA3LWEwNzQtN2Y0ZmNkODljNzEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA3VDEyMTMwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2OGNkZTBkZjE0M2U1OGUxZDhlOGE0YmU3NmViMThiYjEyZjZjMzE5YjkwNmRkZDUyZWQzYzIzODAyZjQ4YTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UbY8LJM9lO_JZ2-DzoaQ3X6Ks6z1RcTmsm0vWs2SI_Q)