0

我尝试使用 c# 中的 webbrowser登录网站(“ https://mytel.com.mm/ ”)。它无法登录。下面是代码。

/// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static WebBrowser wb;
    [STAThread]
    static void Main()
    {
        wb = new WebBrowser();
        wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
        wb.Navigate("https://mytel.com.mm/");

        Application.Run();
    }
    static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        string Logurl = wb.Url.AbsoluteUri;
        if (!wb.Url.ToString().Contains("myviettel"))
        {
            var InputElements = wb.Document.GetElementsByTagName("input");
            foreach (HtmlElement i in InputElements)
            {
                if (i.GetAttribute("ng-model").Equals("loginForm.username"))
                {
                    i.Focus();
                    i.InnerText = "xxxxxxxxx";
                }
                if (i.GetAttribute("ng-model").Equals("loginForm.password"))
                {
                    i.Focus();
                    i.InnerText = "xxxxxxxxx";
                    i.RemoveFocus();
                }
            }

            var buttonElements = wb.Document.GetElementsByTagName("button");
            foreach (HtmlElement b in buttonElements)
            {
                if (b.GetAttribute("className").Equals("btn btn-nat-input-popup-bottom margin-bottom-10 ng-binding"))
                {
                    b.InvokeMember("click");
                }
            }
        }
        else
        {
            //logged in
        }
    }

登录成功后,网址为“ https://www.mytel.com.mm/myviettel ”。
而且我认为 Logurl 变量应该包含(“ https://www.mytel.com.mm/myviettel ”)。

谢谢

4

1 回答 1

0

为了得到答案,我使用 Selenium Chromedriver 服务,它可以通过编程方式成功登录。

于 2018-09-04T05:01:20.183 回答