Simulate click on DIV
Asked Answered
N

1

6

I am developing a desktop application in Delphi XE4 using TChromium component to display Google Voice webpage.

I need to start a call programmatically and I can't find a way to trigger the javascript code behind the button (it is a DIV) "CONNECT":

enter image description here

TChromium allows to execute javascript code and I already managed to simulate the click on "CALL" button using a javascript code that simulates the Key Event using the character "c" which display the panel. This works because Google Voice has shortcuts and "c" is a valid shortcut to start a call. Also with javascript I can set the number in the input field. My main problem is that I don't know how to simulate a click on "CONNECT":

enter image description here

As you can see, there is no ID, no onClick and there is no shortcut to trigger the Connect button.

I can get a reference to this DIV using the following code:

document.getElementById(":87.mi").children[0].children[0].children[5].children[1].children[0].children[0].children[0].children[1];

But it is not possible to trigger anything appending .click(). I assume it is because click() will trigger onClick method that it is not defined. Is there any way to know what javascript code executes when someone clicks over this div?

If the focus is in the "Number to call" input, I can press "TAB" to navigate to "Phone to call with", then to "Remember to choice" and finally to "Connect" where I can press Enter key to make it work also. I tried to use the same code as in the beginning to simulate the CALL button but this time with TAB (keycode 9 instead of 67) and it does not work as the focus does not move.

I tried to do it programmatically with delphi also using mouse_event, keybd_event, PostKeyExHWND, PostKeyEx32 and PostMessage with no results as the focus does not move away from "Number to call"

The only option that works by now is to move the mouse with delphi using SetCursorPos and simulate a click on that button calculating the coordinates but this will be my last option to choose as I would prefer a javascript code to do it.

Any suggestions are welcome!

Naraka answered 11/8, 2013 at 19:41 Comment(5)
You prefer a vanilla JS solution to jQuery? Do you have a console available? Does the event trigger with document.getElementsByClassName('goog-button-base-content')[0].click()?Throng
I think JQuery is not included in this webpage. If it is possible to include it dynamically it is ok. The link of this webpage is google.com/voice but you must be in USA and first register a phone number.Naraka
Then I'm out of this game... So at least I'll add a link to the question asking for the most correct solution, for using the official API for this service.Linnealinnean
Beware: The terms of service say you mustn't "reformat or frame any portion of the web pages that are part of the Google Voice Service."Subgroup
Yes, why don't you ask Google for help in how to put their service inside your desktop app!!Apomixis
M
-1

I suggest the next solution.

In a javascript file that have to be imported from the view, put the next code:

$(".goog-button-base-content").click(function(){
  //CODE HERE
});

What you do here is that everytime that we pressed the div that has that class, you will start the logic inside "CODE HERE"

(Sorry for my bad english)

I hope be usefully. See you

Mancuso answered 12/8, 2013 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.