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']") // Source Listen icon
document.querySelectorAll("div[data-tooltip='Listen']") // Translated Listen icon
usually you can trigger the click event programmatically by
var iconDiv = document.querySelectorAll("div[data-tooltip='Listen']")
You can verify this in Chrome inspector console by entering
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.
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.