Hello,
I used the following code with TWebBrowser to read a page value
function GetElementIdValue(AWebBrowser: TWebBrowser; const ATagName, ATagId, ATagAttrib: string): string;
var vDocument: IHTMLDocument2;
vBody: IHTMLElement2;
vTags: IHTMLElementCollection;
vTag: IHTMLElement;
vIdx: Integer;
begin
result := '';
if not Supports(AWebBrowser.Document, IHTMLDocument2, vDocument) then
exit; //raise Exception.Create('Invalid HTML document');
if not Supports(vDocument.body, IHTMLElement2, vBody) then
exit; //raise Exception.Create('Can''t find <body> element');
vTags := vBody.getElementsByTagName(UpperCase(ATagName));
for vIdx := 0 to Pred(vTags.length) do begin
vTag := vTags.item(vIdx, EmptyParam) as IHTMLElement;
if vTag.id = ATagId then
result := vTag.getAttribute(ATagAttrib, 0)
end
end;
What would be the similar code for Chromium browser?
Thanks a lot.
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
How to read a field value from a page?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to read a field value from a page?
The DOMVisitor demo shows how to get and set values using :
- JavaScript.
- The CEF functions to visit the DOM.
- The DevTools functions.
Re: How to read a field value from a page?
Thanks Salvador, i got JavaScript method working in my own test application, however this method is async.
Should i use CEF functions for sync mode?
Should i use CEF functions for sync mode?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to read a field value from a page?
Most of the Chromium features are async, especially if you have to deal with the DOM because it "lives" in a different process.
I would recomend to modify the existing code in your application so it can use async functions.
I would recomend to modify the existing code in your application so it can use async functions.