Stack Exchange
Javascript call from c# geckofx webbrowser is not working
I am trying to send a message to my youtube channel https://www.youtube.com/channel/UCvbmZAxplx3ZS925Tt1DPjg/about using my another account. I am using this code right now:
 geckoWebBrowser1.Navigate("https://accounts.google.com/ServiceLogin");
        geckoWebBrowser1.DocumentCompleted += (a, b) =>
            {
                if (step == 0)
                {
                    geckoWebBrowser1.Document.GetElementById("Email").SetAttribute("value", "username");
                    geckoWebBrowser1.Document.GetElementById("Passwd").SetAttribute("value", "password");
                    GeckoHtmlElement btn = (GeckoHtmlElement)geckoWebBrowser1.Document.GetElementById("signIn");
                    btn.Click();
                    step = 1;
                }
                else if (step == 1)
                {
                    geckoWebBrowser1.Navigate("https://www.youtube.com/channel/UCvbmZAxplx3ZS925Tt1DPjg/about");
                    geckoWebBrowser1.Refresh();
                          step = 2;
                }
                else if(step == 2 )
                {

                    if (!geckoWebBrowser1.IsBusy || !geckoWebBrowser1.IsAjaxBusy)
                    {

                        Gecko.AutoJSContext js = new AutoJSContext(geckoWebBrowser1.Window.JSContext);

                           string outstring = "";
                            js.EvaluateScript(@"document.getElementsByClassName('channel-msg-button')[0].click(); document.getElementsByClassName('compose-message')[0].innerText = ""Hi testing"";  document.getElementsByClassName('yt-dialog-send')[0].click(); ", out outstring);
                            MessageBox.Show(outstring);

                    }
                }

I switched to javascript code in c# because the c# code was not working for it. There was no error but it just don't do anything. The problem with this javascript code is that only the first line of code (i.e, the code to open the dialog) only  works. Is there any solution to execute all the script one by one?

You should use their API, your approach will break with every update to the web-page.  Also, it isn't working because you don't have the proper OAuth data in the browser, so it won't let you comment. https://developers.google.com/youtube/v3/live/guides/auth/client-side-web-apps

@Greg Btw what if i use C# code instead of this javascript code?

You'll still need to get the OAuth Token.

@Greg i was able to comment without the oauth through the browser.

Put you JS code in a function then call that. eg:. EvaluateScript("function dosomthing() { return "lots of statements here"; } dosomthing(this);"

@Tom unfortunately its not working.
