Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I am creating one word vsto add-in using visual studio 2019.

The tool will copy the selected sentence in word document and open the internet explorer with the given url and paste it in one search box.

I need help to how to use getelementbyid option in visual studio. This is the below code

What I have tried:

SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
           object Empty = 0;
           object URL = "https://searchengine.com/";



           IE.Visible = true;
           IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);

           System.Threading.Thread.Sleep(5000);

           IE.Document.getelementbyid("search")="search text";

           IE.Quit();
Posted
Comments
Bob@work 11-Oct-20 21:21pm    
Which part isn't working? Are you able to launch ID? IF so, you'll need to set the value, text, innerHTML, or some other property of the HTML object instead of setting the element itself to be text string.

If the element with id="search" is a text box:

IE.Document.getelementbyid("search").value="search text";

might help make some progress.
Member 8337387 12-Oct-20 8:47am    
IE.Document.getelementbyid("search")="search text";

the above code is not working.
showing error in getelementbyid
Richard MacCutchan 12-Oct-20 4:52am    
It would be much easier to build a URL that passes the text to Google and send it to the default browser. Not everyone uses Internet Explorer anymore. And even Microsoft have stopped updating it.

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