Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用c中的webbrowser以编程方式登录网站#_C#_Login_Htmlelements - Fatal编程技术网

C# 无法使用c中的webbrowser以编程方式登录网站#

C# 无法使用c中的webbrowser以编程方式登录网站#,c#,login,htmlelements,C#,Login,Htmlelements,我试图用c#中的webbrowser登录到一个网站(“”)。 它无法登录。下面是代码 /// <summary> /// The main entry point for the application. /// </summary> private static WebBrowser wb; [STAThread] static void Main() { wb = new WebBrowser();

我试图用c#中的webbrowser登录到一个网站(“”)。 它无法登录。下面是代码

/// <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
        }
    }
//
///应用程序的主要入口点。
/// 
专用静态网络浏览器wb;
[状态线程]
静态void Main()
{
wb=新的WebBrowser();
wb.DocumentCompleted+=新的WebBrowserDocumentCompletedEventHandler(wb\U DocumentCompleted);
wb.导航(“https://mytel.com.mm/");
Application.Run();
}
静态无效wb_DocumentCompleted(对象发送者,WebBrowserDocumentCompletedEventArgs e)
{
字符串Logurl=wb.Url.AbsoluteUri;
如果(!wb.Url.ToString()包含(“myviettel”))
{
var InputElements=wb.Document.GetElementsByTagName(“输入”);
foreach(InputElements中的HtmlElement i)
{
如果(i.GetAttribute(“ng模型”).Equals(“loginForm.username”))
{
i、 焦点();
i、 InnerText=“xxxxxxxxx”;
}
如果(i.GetAttribute(“ng模型”).Equals(“loginForm.password”))
{
i、 焦点();
i、 InnerText=“xxxxxxxxx”;
i、 移除焦点();
}
}
var buttonElements=wb.Document.GetElementsByTagName(“按钮”);
foreach(按钮元素中的HtmlElement b)
{
如果(b.GetAttribute(“className”).Equals(“btn btn nat输入弹出式底部边距-bottom-10 ng绑定”))
{
b、 调用成员(“单击”);
}
}
}
其他的
{
//登录
}
}
成功登录后,url为“”。
我认为Logurl变量应该包含(“”)


谢谢你

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

你想达到什么目的?@Fildor我想登录这个网站是的,这是显而易见的。但你为什么要用C代码做这件事?为什么要使用实际的网页?他们没有API供开发人员使用吗?但对于您的实际问题:我不确定,但我怀疑设置
InnerText
就足够了。我想(但真的不知道-以前从未尝试过)您需要“模拟”实际按键事件。“但我可能在这一点上大错特错了。”菲尔多还是谢谢你。我找到了另一种以编程方式登录的方法。我正在尝试使用chrome驱动程序。