小编ism*_*der的帖子

c#webbrowser控件不会导航到另一个页面

我有一个控制台应用程序,我已经在其中定义了一个webbrowser.首先,我导航到一个页面并填写登录表单并调用提交按钮进行登录.

之后,我想使用相同的webbrowser转到同一站点中的另一个页面,但它不会导航到该页面.相反,它导航到登录后重定向的页面.

这是我的澄清代码; 这段代码给了我www.websiteiwanttogo.com/default.aspx的源代码而不是product.aspx这里有什么问题?

static WebBrowser wb = new WebBrowser();

    [STAThread]
    static void Main(string[] args)
    {
        wb.AllowNavigation = true;
        wb.Navigate("https://www.thewebsiteiwanttogo.com/login.aspx");
        wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
        Application.Run();


    }

    static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (wb.Url.ToString().IndexOf("login.aspx") > -1)
        {
            wb.Document.GetElementById("txtnumber").SetAttribute("value", "000001");
            wb.Document.GetElementById("txtUserName").SetAttribute("value", "myusername");
            wb.Document.GetElementById("txtPassword").SetAttribute("value", "mypassword");
            wb.Document.GetElementById("btnLogin").InvokeMember("click");


        }
        else
        {
            //wb.Document.Body  you are logged in do whatever you want here.
            wb.Navigate("https://www.thewebsiteiwanttogo.com/product.aspx");

            Console.WriteLine(wb.DocumentText);
            Console.ReadLine();
            Application.Exit();

        }
    }
Run Code Online (Sandbox Code Playgroud)

c# webbrowser-control navigateurl

5
推荐指数
1
解决办法
5569
查看次数

标签 统计

c# ×1

navigateurl ×1

webbrowser-control ×1