Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is a link to Google Translate translating the word: "dog"
Google Translate[^]

I need to be able to press the source Listen button and the Listen button of the translated language.

There's no element ID.

What I have tried:

try
            {
                foreach (HtmlElement h in webBrowserGoogleTranslate.Document.All)
                {
                    

                    if (h.InnerHtml == @"<div class=""jfk-button-img""></div>")
                    {
                        h.InvokeMember("MouseDown");
                        h.InvokeMember("MouseUp");
                        h.InvokeMember("Click");
                    }
                    
                }
            }
            catch { }
Posted
Updated 2-Jan-19 5:09am
v3

1 solution

There are two Listen buttons (source language and destination language). The unique characterisation of these buttons is that they are a div element with src-tts as class for the source and res-tts for the result (amongst other classes). So loop over the elements and check for said class:
C#
HtmlElement sourceListenButton = null;
foreach (HtmlElement h in webBrowserGoogleTranslate.Document.GetElementsByTagName("div"))
{
    if (h.GetAttribute("class").Contains("src-tts")) // or res-tts; Contains because there are other classes too
    {
        sourceListenButton = h;
        break;
    }
}

if (sourceListenButton == null)
{
    // not found
}
 
Share this answer
 
v5
Comments
john1990_1 2-Jan-19 11:31am    
listenButtons remains an empty list...
Thomas Daniels 2-Jan-19 11:34am    
I posted an alternative that you can try, but currently I don't have the chance to actually test it myself.
john1990_1 2-Jan-19 11:36am    
Sorry still 0.
Thomas Daniels 2-Jan-19 11:38am    
Are the buttons already visible in the control at the time you call this code?
john1990_1 2-Jan-19 11:41am    
Yes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900