Chromium Automation for VBA - CDP Framework (ChromeDevProtocols Framework)
This is a method to directly automate Chromium-based web browsers, such as Chrome, Edge, and Firefox, using VBA for Office applications by following the ChromeDevProtocols framework. This git is an enhanced framework based on the original pioneering article by ChrisK23 on CodeProject. You can find the original article as well as his example here at https://www.codeproject.com/Tips/5307593/Automate-Chrome-Edge-using-VBA\
What It Can Do
This method enables direct automation with Chromium-based web browsers for VBA without the need for a third-party software like SeleniumBasic. The framework also includes many examples and useful functions added to the original repository while keeping the whole design as simple as possible to help you understand and get started quickly with deploying the CDP framework for your VBA solutions.
Features added on v2.7:
- Enhanced .newTab and .getTab to be able to set the tab as new main CDP session via the setMain argument.
- Session handling and attachment will now be based on the tab ID instead of session ID as session ID is volatile.
- Added compatibility for Access & Word.
- Added isExist method for CDPElement class to check if an element is found. Unlike onExist which will wait until the element is found which can only be useful for certain scenarios, isExist will just do the check and allow the devs freedom to handle the information returned.
Features added on v2.6:
- Added .sendKeys for CDPElement class. This sendkeys method can send text inputs directly even to a specific element and mimicks human native input.
- Enhanced .value property of CDPElement class to auto-detect React-type form fields and set value in the right way to trigger React field script.
- Enhanced .getIFrame to detect if the targetted iFrame is hosted in another domain which will then require indirect automation on the frame.
- New examples in the demo module added to showcase (1) & (2).
Features added on v2.5:
- Added getElementByID, getElementByQuery (querySelector equivalence), getElementByXPath, getElementsByQuery, getElementsByXPath.
- Added helpful examples to the getElement methods' function definitions for ease of learning and employment.
- Overhauled the error debugging system of CDP 1.0. The Immediate Window is now filled with highly detailed and useful debugging information.
- Added AddJsLib, a powerful function to integrate external JS Library to greatly widen the automation scope of the framework.
- Added snapPage to take snapshot of the web page or an element within the page. This demonstrates the power of the AddJsLib function.
- No longer required for dev to use .deserialize or .serialize to rehook ongoing CDP Session. This is now done intuitively by the CDPBrowser class.
- Added CDPElement class with many element specific methods for HTML element interactions, such as:
- .getIFrame to easily access and work on an iFrame element.
- .value, .innerHTML, .innerText, .click, .submit, .setAttribute, .fireEvent for diverse interaction needs.
- .getParent, .getNextSibling, .getPrevSibling, .getFirstChild for diverse node tree traversal requirements.
- .onExist and .onExistNot to smart wait until the target element appears/disappears.
- Added .html to easily extract the entire html of the current web page. Useful for devs who need the html for processing.
- Enhanced .start to automatically detect browser installation path and start the browser there. v1.0 was failing when the user chooses a non-standard path.
- Added many functions to easily automate multiple tabs and debugging them:
- .getTabNew to quickly get object referrence of the new tab open by the web page.
- .getTab to get object referrence of the target tab based on its title or on its url string.
- .closeTab to close the target tab and .printTabs to print the info of all the tabs currently open.
- .newTab to open a new tab and navigate to a specific Url by the CDP Session.
- .printParams to easily retrieve all debugging information of the current tab.
- Many other minor bug fixes and improvements over the remaining functions.
Functions that are added over the original:
- A method to make the browser visible and invisible.
- New methods to create and manage multiple tabs at the same time.
- A method to handle browser window state, such as maximizing, minimizing, and resizing.
- A method to parse additional arguments to allow setting up a browser automation session with advanced requirements.
- A method to easily start Edge or Chrome for automation at the user's choice.
For Demo
Open CDP Framework.xlam and look for the module named "Demo" inside there.
For Installation
- Download CDP Framework.xlam and open it.
- Copy CDPBrowser, CDPCore, CDPElement, CDPJConv classes over to your VBA project.
- Make sure your project has Microsoft Scripting Runtime reference.
Notes
This framework does not work for Edge IE Mode. For a framework that works on Edge IE Mode, see this git of mine instead:
https://github.com/longvh211/Edge-IE-Mode-Automation-with-IES-for-VBA/tree/main
Credits
ChrisK23 for the great original source: https://www.codeproject.com/Tips/5307593/Automate-Chrome-Edge-using-VBA\
PerditionC for plenty of helpful CDP examples: https://github.com/PerditionC/VBAChromeDevProtocol