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 [email protected]: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