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.

document.getElementsByClassName

Post Reply
amiran6543
Posts: 15
Joined: Sun Dec 05, 2021 12:07 pm

document.getElementsByClassName

Post by amiran6543 »

Hello, such a question, there is a website on it there is
<div class="_2vbn4" style="visibility: visible;">Enter the message</div>
How do I click on this element?

Code: Select all

procedure TForm2.Button1Click(Sender: TObject);
var
CodeStr:string;
begin
      CodeStr:='document.getElementsByClassName("_2vbn4")[0].click();' ;
Chromium1.Browser.MainFrame.ExecuteJavaScript(CodeStr, '', 0);
               end;

Does not work!
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: document.getElementsByClassName

Post by salvadordf »

Try getting the element coordinates and then simulate a mouse click using the TChromium.SendMouseClickEvent function.

See this answer to know how to get the coordinates :
https://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element

See the SimpleOSRBrowser demo for all the details about using TChromium.SendMouseClickEvent
Post Reply