Clicking on HTML element in Delphi TEdgeBrowser?

1.7k views Asked by At

How can I "click" on the following HTML element via Delphi code?

<div id="card" class="ev_tab_title display active " draggable="true" tabindex="0" title="Boards" style="min-width: 5px;"><span class="ev_tab_bar"></span>Boards</div>

Trying to handle the press process as a button I get no response.

EdgeBrowser1.ExecuteScript('document.getElementById("card").click()');

Any ideas?

1

There are 1 answers

0
Softacom On BEST ANSWER

Basically everyone works by clicking on web page elements by sending a script

document.getElementById(''name id'').click();'

If it doesn't work in your case, you can try the script to get to the element not by ID, but by Class An example of the script below:

EdgeBrowser1.ExecuteScript('document.getElementsByClassName(''ev_tab_title display active '')[0].click();');

Or via querySelector For example like this:

//sJavaClickEnter is a string variable to which we assign the script string
sJavaClickEnter:='var elem = document.querySelectorAll(''.input-addon.btn.btn-default.fileinput-exists'');' +#13#10+ 'elem[1].click();';
EdgeBrowser1.ExecuteScript(sJavaClickEnter);

If this doesn't help either, you can move the mouse cursor to the element and programmatically make the mouse button click

SetCursorPos(500, 70); //coordinates where to move the cursor
Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); //press button
Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); //release button