Example #1
0
        private void kiểmTraChứcNăngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmKTChucNang fr11 = new frmKTChucNang();

            this.Hide();
            fr11.Show();
        }
        private void btnDoMK_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            // chọn đường dẫn lưu ảnh chụp màn hình
            saveDialog.Filter      = "PNG Files (.png)|*.png|All Files (*.*)|*.*";
            saveDialog.FilterIndex = 1;
            //


            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                FirefoxDriver firefoxDriver;
                firefoxDriver = new FirefoxDriver();
                firefoxDriver.Manage().Window.Maximize();
                firefoxDriver.Url = "http://online.hcmute.edu.vn/";
                firefoxDriver.Navigate();

                // bắt sự kiện click vào button đăng nhập
                try
                {
                    // tìm đối tượng theo ID
                    var btnDangNhap = firefoxDriver.FindElementById("ctl00_lbtDangnhap"); //đang cố ý để erro để bắt try cat
                                                                                          //click vào button đăng nhập
                    btnDangNhap.Click();
                }
                catch (Exception ex)
                {
                    DialogResult dlr = MessageBox.Show("Có lỗi, bạn có muốn tiếp tục. \n" + ex, "Thông báo", MessageBoxButtons.YesNo);

                    if (dlr == DialogResult.Yes)
                    {
                        // lưu ảnh chụp màn hình cuối cùng(đoạn này copy hoàn toàn trên Google)
                        screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                                  Screen.PrimaryScreen.Bounds.Height,
                                                  PixelFormat.Format32bppArgb);
                        screenGraphics = Graphics.FromImage(screenBitmap);
                        screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                                      0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                        screenBitmap.Save(saveDialog.FileName, ImageFormat.Png);

                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        frmKTChucNang fr1 = new frmKTChucNang();
                        fr1.Show();
                    }
                    else
                    {
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        Application.Exit();   //đóng giao diện
                    }
                }
                try
                {
                    //tìm đến chỗ ô tên đăng nhập
                    var txtTenDangNhap = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_txtUserName\"]");
                    //gõ tên đăng nhập vào
                    txtTenDangNhap.SendKeys("15110231");

                    Thread.Sleep(1000); // ngủ 1 giây
                }
                catch (Exception ex1)
                {
                    DialogResult dlr = MessageBox.Show("Có lỗi, bạn có muốn tiếp tục. \n" + ex1, "Thông báo", MessageBoxButtons.YesNo);

                    if (dlr == DialogResult.Yes)
                    {
                        // lưu ảnh chụp màn hình cuối cùng(đoạn này copy hoàn toàn trên Google)
                        screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                                  Screen.PrimaryScreen.Bounds.Height,
                                                  PixelFormat.Format32bppArgb);
                        screenGraphics = Graphics.FromImage(screenBitmap);
                        screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                                      0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                        screenBitmap.Save(saveDialog.FileName, ImageFormat.Png);
                        //đóng hoàn toàn ứng dụng
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        frmKTChucNang fr1 = new frmKTChucNang();
                        fr1.Show();
                    }
                    else
                    {
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        Application.Exit();   //đóng giao diện
                    }
                }
                int x = 0;
                while (x < 999999)
                {
                    try
                    {
                        //tìm đến ô mật khẩu
                        var txtMK = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_txtPassword\"]");
                        //gõ mật khẩu vào
                        txtMK.SendKeys(XLMK(x));
                        //tìm đến button đăng nhập và nhấn vào nó
                        var btn1 = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_btLogin\"]");
                        btn1.Click();
                        //tìm đến chỗ THÔNG TIN CÁ NHÂN và nhấn vào nó
                        var btn2 = firefoxDriver.FindElementById("ctl00_ContentPlaceHolder1_ctl00_ctl00_lnkInfo");
                        btn2.Click();
                        firefoxDriver.Manage().Window.Minimize();
                        Thread.Sleep(2000);
                        MessageBox.Show("Mật khẩu là: " + XLMK(x));

                        break;
                    }
                    catch (Exception er)
                    {
                        x++;
                    }
                }
            }
        }
        void NavigateByXpath(string XPath)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            // chọn đường dẫn lưu ảnh chụp màn hình
            saveDialog.Filter      = "PNG Files (.png)|*.png|All Files (*.*)|*.*";
            saveDialog.FilterIndex = 1;
            //


            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                //đóng giao diện
                this.Hide();
                //khởi động trình duyệt
                firefoxDriver = new FirefoxDriver();
                //phóng to trình duyệt ra toàn màn hình
                this.firefoxDriver.Manage().Window.Maximize();
                //truy cập trực tiếp tới địa chỉ tuyệt đối của trang online
                firefoxDriver.Url = "https://online.hcmute.edu.vn/";
                firefoxDriver.Navigate();
                try
                {
                    // tìm đối tượng theo ID
                    var btnDangNhap = firefoxDriver.FindElementById("ctl00_lbtDangnhap");//đang cố ý để erro để bắt try cat
                    //click vào button đăng nhập
                    btnDangNhap.Click();
                    //tìm đến chỗ ô tên đăng nhập
                    var txtTenDangNhap = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_txtUserName\"]");
                    //gõ tên đăng nhập vào
                    txtTenDangNhap.SendKeys("15110231");

                    Thread.Sleep(1000); // ngủ 1 giây

                    //tìm đến ô mật khẩu
                    var txtMK = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_txtPassword\"]");
                    //gõ mật khẩu vào
                    txtMK.SendKeys("000030");

                    Thread.Sleep(1000); //tiếp tục ngủ 1 giây để xem kết quả (Sẽ tắt khi mạng yếu)
                                        //tìm đến button đăng nhập và nhấn vào nó
                    var btn1 = firefoxDriver.FindElementByXPath("//*[@id=\"ctl00_ContentPlaceHolder1_ctl00_ctl00_btLogin\"]");
                    btn1.Click();
                    //tìm đến chỗ THÔNG TIN CÁ NHÂN và nhấn vào nó
                    var btn2 = firefoxDriver.FindElementByXPath(XPath);
                    btn2.Click();
                    Thread.Sleep(1000);
                    // lại ngủ 1 giây
                    // lưu ảnh chụp màn hình cuối cùng(đoạn này copy hoàn toàn trên Google)
                    screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                              Screen.PrimaryScreen.Bounds.Height,
                                              PixelFormat.Format32bppArgb);
                    screenGraphics = Graphics.FromImage(screenBitmap);
                    screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                                  0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                    screenBitmap.Save(saveDialog.FileName, ImageFormat.Png);
                    DialogResult dlr = MessageBox.Show("Xong , bạn có muốn tiếp tục. \n", "Thông báo", MessageBoxButtons.YesNo);

                    if (dlr == DialogResult.Yes)
                    {
                        // lưu ảnh chụp màn hình cuối cùng(đoạn này copy hoàn toàn trên Google)
                        screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                                  Screen.PrimaryScreen.Bounds.Height,
                                                  PixelFormat.Format32bppArgb);
                        screenGraphics = Graphics.FromImage(screenBitmap);
                        screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                                      0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                        screenBitmap.Save(saveDialog.FileName, ImageFormat.Png);
                        //đóng hoàn toàn ứng dụng
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        frmKTChucNang fr1 = new frmKTChucNang();
                        fr1.Show();
                    }
                    else
                    {
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        Application.Exit();   //đóng giao diện
                    }
                }
                //catch
                catch (Exception e)
                {
                    DialogResult dlr = MessageBox.Show("Có lỗi, bạn có muốn tiếp tục. \n" + e, "Thông báo", MessageBoxButtons.YesNo);

                    if (dlr == DialogResult.Yes)
                    {
                        // lưu ảnh chụp màn hình cuối cùng(đoạn này copy hoàn toàn trên Google)
                        screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                                  Screen.PrimaryScreen.Bounds.Height,
                                                  PixelFormat.Format32bppArgb);
                        screenGraphics = Graphics.FromImage(screenBitmap);
                        screenGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
                                                      0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                        screenBitmap.Save(saveDialog.FileName, ImageFormat.Png);
                        //đóng hoàn toàn ứng dụng
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        frmKTChucNang fr1 = new frmKTChucNang();
                        fr1.Show();
                    }
                    else
                    {
                        firefoxDriver.Quit(); //đóng cửa sổ trình duyệt vừa mở
                        Application.Exit();   //đóng giao diện
                    }
                }


                // this.Show();
            }
        }//hàm đi đến các công cụ chính trong trang online