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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to find with GetElementById

X11
Posts: 49
Joined: Thu Jul 25, 2019 10:15 am

Re: How to find with GetElementById

Post by X11 »

Use ICEFDomNode.AsMarkup to get the contents of this node as markup.
Thanx, I forgot about TempChild.AsMarkup - this is innerHTMLtext.

It may be correct if you rename "AsMarkup" to "innerHTMLtext"?
X11
Posts: 49
Joined: Thu Jul 25, 2019 10:15 am

Re: How to find with GetElementById

Post by X11 »

DOM iteration with recource:

Code: Select all

procedure StartDOMIteration(const aDocument: ICefDomDocument; const frame: ICefFrame);
var
  TempNode, TempChild : ICefDomNode;
  msg: ICefProcessMessage;
  attrList: TStrings;
  InnerHTMLText, val: string;
begin
  try
    if aDocument <> nil then
    begin
      TempNode := aDocument.Body;

        if TempNode <> nil then
        begin
          TempChild := TempNode.FirstChild;

          while TempChild <> nil do
          begin
            RecourceDOMIteration(frame, TempChild);
            
            Msg := TCefProcessMessageRef.New(msg_for_chromium);
            if TempChild.ElementInnerText = '' then
            begin
              TempChild := TempChild.NextSibling;
              Continue;
            end;

            msg.ArgumentList.SetString(0, 'name: ' + Trim(TempChild.Name));
            msg.ArgumentList.SetString(1, 'TagName: ' + Trim(TempChild.ElementTagName));

            attrList := TStringList.Create;
            try
              TempChild.GetElementAttributes(attrList);

              msg.ArgumentList.SetString(2, 'attrList: ' + attrList.CommaText);
            finally
              attrList.DisposeOf;
            end;

            InnerHTMLText := Trim(TempChild.AsMarkup);
            msg.ArgumentList.SetString(3, 'InnerHTMLText: ' + TempChild.AsMarkup);

            val := Trim(TempChild.GetValue);
            msg.ArgumentList.SetString(4, 'value: ' + val);


//            if TempChild.HasElementAttribute('href') then
//              msg.ArgumentList.SetString(4, 'href: ' + Trim(TempChild.GetElementAttribute('href')));

            msg.ArgumentList.SetString(5, '**********************');


            frame.SendProcessMessage(PID_BROWSER, msg);

            TempChild := TempChild.NextSibling;

          end;
        end;

    end;
  except
    on e : exception do
      if CustomExceptionHandler('StartDOMIteration', e) then raise;
  end;
end;

procedure RecourceDOMIteration(const frame: ICefFrame; CefDomNode: ICefDomNode);
var
  TempChild : ICefDomNode;
  msg: ICefProcessMessage;
  attrList: TStrings;
  InnerHTMLText, val: string;
begin
  try
    Msg := TCefProcessMessageRef.New(msg_for_chromium);
    if CefDomNode <> nil then
      msg.ArgumentList.SetString(0, 'RecourceDOMIteration, CefDomNode ' + CefDomNode.Name)
    else
      msg.ArgumentList.SetString(0, 'RecourceDOMIteration, CefDomNode = nil');
    frame.SendProcessMessage(PID_BROWSER, msg);


        if CefDomNode <> nil then
        begin
          TempChild := CefDomNode.FirstChild;

          while TempChild <> nil do
          begin
            RecourceDOMIteration(frame, TempChild);

            Msg := TCefProcessMessageRef.New(msg_for_chromium);
            if TempChild.ElementInnerText = '' then
            begin
              TempChild := TempChild.NextSibling;
              Continue;
            end;

            msg.ArgumentList.SetString(0, 'name: ' + Trim(TempChild.Name));
            msg.ArgumentList.SetString(1, 'TagName: ' + Trim(TempChild.ElementTagName));

            attrList := TStringList.Create;
            try
              TempChild.GetElementAttributes(attrList);

              msg.ArgumentList.SetString(2, 'attrList: ' + attrList.CommaText);
            finally
              attrList.DisposeOf;
            end;

            InnerHTMLText := Trim(TempChild.AsMarkup);
            msg.ArgumentList.SetString(3, 'InnerHTMLText: ' + TempChild.AsMarkup);

            val := Trim(TempChild.GetValue);
            msg.ArgumentList.SetString(4, 'value: ' + val);


//            if TempChild.HasElementAttribute('href') then
//              msg.ArgumentList.SetString(4, 'href: ' + Trim(TempChild.GetElementAttribute('href')));

            msg.ArgumentList.SetString(5, '**********************');


            frame.SendProcessMessage(PID_BROWSER, msg);

            TempChild := TempChild.NextSibling;
          end;
        end;

  except
    on e : exception do
      if CustomExceptionHandler('RecourceDOMIteration', e) then raise;
  end;
end;
Post Reply