Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a translation program that opens a Google Translate website in a webbrowser control in it, when Ctrl+C is pressed 3 times fast in Windows my program puts what is in clipboard in Google Translate web page in the webbrowser control automatically and it gets translated, suddenly my program stopped working correctly, how to get the source textbox as an HTMLElement to get/set what is in it and apply things like a 'click' and 'focus' on it.

I think there is no more an element with the ID: "source" (which was the textbox of the text to be translated).

The typing of text in the textbox source is so slow too dunno why (it gets one letter every 0.7 seconds or something)

What I have tried:

HtmlElement textArea = formMain.webBrowserGoogleTranslate.Document.GetElementById("source");
Posted
Updated 5-Nov-20 11:28am
v2
Comments
F-ES Sitecore 5-Nov-20 13:27pm    
Use the translation API instead

https://cloud.google.com/translate/
john1990_1 5-Nov-20 13:36pm    
Thx but I want a robust Google Translate website with all its features and visual elements, I implemented the API long ago and it wasn't good enough.
F-ES Sitecore 5-Nov-20 14:20pm    
Then build your own rather than stealing other people's effort :)
john1990_1 5-Nov-20 14:23pm    
I'm just putting a website in a webbrowser in my program, I just want to make it easier for the user by putting what is in his clipboard into the textbox.
Richard MacCutchan 6-Nov-20 6:19am    
Ctrl-V.

That's the problem with what you're doing.

Every time the website you're using changes, you have to go digging through the new HTML and find the stuff you need. The owners of the site are free to change everything, including css, IDs, events, javascript, ... without telling you and you have to do the leg work yourself. You cannot rely on code to do it for you.
 
Share this answer
 
Comments
john1990_1 6-Nov-20 5:07am    
I tried looking for the ID of the element in Inspect in Chrome but I can't find it, and yes, every ~ 4-5 years I'm gonna change the ID of the element, this time I can't find the ID, can anyone help me please to tell me how to access the HTMLElement? as I said I'm just putting a website in a webbrowser in my program, I just want to make it easier for the user by putting what is in his clipboard into the textbox, my program is for me and my friends with no payments and no donations accepted. how to get to the HTMLElement from class name?
This solved it for me (Win10):

HtmlElement textArea = formMain.webBrowserGoogleTranslate.Document.GetElementsByTagName("TEXTAREA")[0];


While on my other Win10 PC the problem didn't exist to begin with, and this solution still worked on it.
 
Share this answer
 
Comments
Dave Kreskowiak 7-Nov-20 11:35am    
And when they don't use a TEXTAREA on the next iteration of the UI, then what are you going to do?

This is the problem with web scraping. You have no idea what you're going to have to look for when the site changes.
john1990_1 7-Nov-20 12:01pm    
I've been with this program for a long time and Google doesn't change the Translate page a lot, every time it does I make an update to my program. I'm a hobbyist and this program is for me and some friends.

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