0

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?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
VaVel
  • 69
  • 3
  • 13
  • The words in bold are not valid Pascal code. – AmigoJack Apr 23 '22 at 18:23
  • Most likely, but why would one copy and paste the HTML part but not the code he used in Delphi already? What means "_no response_"? Where? Is the website fully understood and ensured that the click handler is really bound to the `div` and not only to the `span`? – AmigoJack Apr 23 '22 at 20:11
  • @Remy Lebeau. Thank you Remy. Sorry, I forgot to write that I am using the command as a string as you already mentioned but still I cannot simulate the "click" action for this HTML element. Although I click on all HTML elements that I want, this is the only & the last element that I want to click in order to complete my project. Do you think that it has to do with something else? – VaVel Apr 24 '22 at 06:57
  • @AmigoJack. Thank you for your response. My entire code consists of 10 executed scripts that simulate the click option and nothing more. Yes you are right I am not familiar with HTML code but what do you mean regarding div & span? – VaVel Apr 24 '22 at 07:04
  • If the whole website is available to others then link to it. Otherwise use the "_inspect this element_" of the browser on that `div` and look up if that has an `onlick` event defined or not. You want to **click** it, but effectively you manually might have always clicked on the `span`, not the `div`. The event may be defined on the `span` only. – AmigoJack Apr 24 '22 at 07:53
  • Using the Inspect Option I found the following onclick event: function(e) { return t.props.onClick(e, t.props.index, t.props.title) }. Can I use this event in order to simulate "click" action on this element? When you say to Link to the website what do you mean? Thank you – VaVel Apr 24 '22 at 13:55
  • This is my last comment since you don't edit your question to include all those details and this website is not intended as a chat. [Dictionary: what the verb "to link" means](https://en.wiktionary.org/wiki/link#Verb) – AmigoJack Apr 24 '22 at 14:13

1 Answers1

0

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
Softacom
  • 613
  • 2
  • 6