我正在尝试使用我的其他帐户向我的YouTube频道https://www.youtube.com/channel/UCvbmZAxplx3ZS925Tt1DPjg/about发送消息。我现在正在使用此代码:
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);
}
}
我切换到c#中的javascript代码,因为c#代码不能正常工作。没有错误,但它什么也没做。这个javascript代码的问题是只有第一行代码(即打开对话框的代码)才有效。是否有任何解决方案可以逐个执行所有脚本?