Click google translate button in chrome?

Is it possible to use Xpath to click the "listen" button in google translate? Below is the HTML code.

You can identified the element by
document.querySelectorAll("div[data-tooltip='Listen']")[0] // Source Listen icon
document.querySelectorAll("div[data-tooltip='Listen']")[1] // Translated Listen icon

usually you can trigger the click event programmatically by
var iconDiv = document.querySelectorAll("div[data-tooltip='Listen']")[1]
iconDiv .click()

You can verify this in Chrome inspector console by entering
monitorEvents(iconDiv, 'click')

but the Listen only happen if click event generated has this property "isTrusted" set to true which is not possible if done programmatically through click() function. I believe that Google check this flag to ensure that it is true before proceeding.

So doing by javascript may not be straightforward..

Hence one solution is to use click by Image action.
The issue with image detection is that the image has to be done through fixed size:

Here is my macro that I myself is using

Basically it make use of same key to run Listen for source Text (long-press OPT-key) and translated Text.

1 Like

Thanks for the reply. Yeah, it looks like the javascript wasn't working so I ended up just using the "click at found image" action.