Пример #1
0
        public void SimilarityCalculation()
        {
            var screenshot = _calculatorSession.GetScreenshot();
            var options    = new SimilarityMatchingOptions {
                Visualize = true
            };

            var similarityResult = _calculatorSession.GetImagesSimilarity(screenshot.AsBase64EncodedString, screenshot.AsBase64EncodedString, options);

            Assert.Greater(similarityResult.Score, 0);
            Assert.IsNotNull(similarityResult.Visualization);
        }
Пример #2
0
        public void TestMethod8()
        {
            var notepad = @"C:\Windows\System32\notepad.exe";

            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", notepad);

            var driver = new WindowsDriver <WindowsElement>(new Uri(" http://127.0.0.1:4723/"), options);

            var eyes = new Eyes();

            eyes.ApiKey = "lFMnO9e1nbFQEdhebrDmhEBOqB7jXUXJGogj103lRWAzM110";
            eyes.SetAppEnvironment("Windows 10", null);

            try
            {
                eyes.Open("AppiumPractice", "TestMethod8");
                Thread.Sleep(3000);
                var currentAppScreenshot = driver.GetScreenshot();
                var croppedScreenshot    = CropScreenshot(currentAppScreenshot);

                eyes.CheckImage(croppedScreenshot, "Notepad Just Opened");

                eyes.Close();
            }
            finally
            {
                eyes?.AbortIfNotClosed();
                driver.Quit();
            }
        }
Пример #3
0
        public void ErrorGetClosedWindowScreenshot()
        {
            // Launch calculator for this specific test case
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", CommonTestSettings.CalculatorAppId);
            WindowsDriver <WindowsElement> calculatorSession = new WindowsDriver <WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);

            Assert.IsNotNull(calculatorSession);
            Assert.IsNotNull(calculatorSession.SessionId);

            try
            {
                calculatorSession.Close();
                calculatorSession.GetScreenshot();
                Assert.Fail("Exception should have been thrown because there is no such window");
            }
            catch (System.InvalidOperationException exception)
            {
                Assert.AreEqual("Currently selected window has been closed", exception.Message);
            }

            calculatorSession.Quit();
            calculatorSession = null;
        }
Пример #4
0
        private void CreateScreenshot(WindowsDriver <WindowsElement> driver)
        {
            var screenshot = driver.GetScreenshot();
            var fileName   = Guid.NewGuid().ToString() + ".png";

            screenshot.SaveAsFile(fileName, OpenQA.Selenium.ScreenshotImageFormat.Png);
            ctx.AddResultFile(fileName);
        }
        public void CreateScreenshot(WindowsDriver <WindowsElement> driver, TestContext ctx)
        {
            var screenshot = driver.GetScreenshot();
            var fileName   = Guid.NewGuid().ToString() + ".png";

            screenshot.SaveAsFile(fileName);
            ctx.AddResultFile(fileName);
        }
Пример #6
0
        public void TestMethod5()
        {
            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", @"C:\Program Files (x86)\M4Solutions\M4Solutions.exe");

            var driver = new WindowsDriver <WindowsElement>(new Uri(" http://127.0.0.1:4723/"), options);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);

            var projectToOpen = @"E:\clients\mapcom\M4 Regression Test Automation\Test Project\Diversicom\ARVIG.prj";

            System.Windows.Forms.Clipboard.SetText(projectToOpen);

            var projectCenterWindow = driver.FindElementByAccessibilityId("ProjectCenter");
            var btnPickProject      = projectCenterWindow.FindElementByAccessibilityId("btnPickProject");

            btnPickProject.Click();

            var openDialog = projectCenterWindow.FindElementByClassName("#32770");

            var fileTextBox = openDialog.FindElementByAccessibilityId("1148");

            fileTextBox.SendKeys(projectToOpen);

            var openButton = openDialog.FindElementByAccessibilityId("1");

            openButton.Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            var mainWindow = driver.FindElementByAccessibilityId("MDIForm1");

            wait.Until(ExpectedConditions.TextToBePresentInElement(mainWindow, "M4 - ARVIG"));
            wait.Until(ExpectedConditions.ElementExists(By.Name("COUNTIES.msi")));

            var eyes = new Eyes();

            eyes.ApiKey = "lFMnO9e1nbFQEdhebrDmhEBOqB7jXUXJGogj103lRWAzM110";
            eyes.SetAppEnvironment("Windows 10", null);

            try
            {
                eyes.Open("AppiumPractice", "TestMethod5");
                Thread.Sleep(3000);
                var currentAppScreenshot = driver.GetScreenshot();

                eyes.CheckImage(currentAppScreenshot.AsByteArray, "Project Finished Loading");

                eyes.Close();
            }
            finally
            {
                eyes?.AbortIfNotClosed();
                driver.Quit();
            }
        }
Пример #7
0
        public void TakeScreenshotOfLaunchPage()
        {
            var screenshotFileName = Path.Combine(_screenshotFolder, $"{Path.GetRandomFileName()}.png");

            var screenshot = AppSession.GetScreenshot();

            screenshot.SaveAsFile(screenshotFileName, ImageFormat.Png);

            Assert.IsTrue(File.Exists(screenshotFileName));
        }
Пример #8
0
        public FileInfo Screenshot(string title)
        {
            // TODO hartez 2017/07/18 10:16:56 Verify that this is working; seems a bit too simple
            var filename = $"{title}.png";

            var screenshot = _session.GetScreenshot();

            screenshot.SaveAsFile(filename, ImageFormat.Png);
            return(new FileInfo(filename));
        }
Пример #9
0
        public void errorHendler(WindowsDriver <WindowsElement> driver, string text)
        {
            Screenshot file = null;

            try
            {
                file = driver.GetScreenshot();
            }
            catch
            {
                try
                {
                    file = driver.GetScreenshot();
                }
                catch { }
            }

            //To save screenshot
            string pngfileName = Guid.NewGuid().ToString();
            //   string pngfilepath = Path.GetDirectoryName(BaseTest.reportPath)+"\\Screenshots\\" + pngfileName + ".png";
            string path = Path.GetDirectoryName(BaseTest.reportPath) + "\\Screenshots";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string pngfilepath = path + "\\" + pngfileName + ".png";

            if (file != null)
            {
                file.SaveAsFile(pngfilepath, ScreenshotImageFormat.Png);
                BaseTest.extentTest.Fail(text, MediaEntityBuilder.CreateScreenCaptureFromPath(pngfilepath).Build());
            }
            else
            {
                BaseTest.extentTest.Fail(text + "<br>" + "was not able to add screenshot");
            }
            throw new System.Exception(text);
        }
Пример #10
0
        public void スクリーンショットをとる()
        {
            var form = _session.FindElementByAccessibilityId("Form1");

            // 起動するまで待つ
            Thread.Sleep(1000);

            var shot = form.GetScreenshot();

            shot.SaveAsFile("form.png", ScreenshotImageFormat.Png);     // スクリーンショットを保存

            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", "Root");
            var deskSession = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), options);

            shot = deskSession.GetScreenshot();
            shot.SaveAsFile("desktop.png", ScreenshotImageFormat.Png);     // デスクトップ全体のスクリーンショットを保存
        }
Пример #11
0
        public void Test_Application_Start_and_Stop()
        {
            var capabilities = new AppiumOptions();

            capabilities.AddAdditionalCapability(MobileCapabilityType.App, @"C:\temp\appium-hol\AppsToTest\WinForms\CarvedRock.exe");
            capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Windows");
            capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "WindowsPC");

            //start the application
            var driver = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);

            var screenshotFilename = Guid.NewGuid().ToString() + ".png";

            driver.GetScreenshot().SaveAsFile(screenshotFilename);
            _ctx.AddResultFile(screenshotFilename);

            // stop the application
            driver.CloseApp();
            driver.Dispose();
        }
Пример #12
0
 public FileInfo Screenshot(string title)
 {
     try
     {
         string     filename   = $"{title}.png";
         Screenshot screenshot = _session.GetScreenshot();
         screenshot.SaveAsFile(filename, ScreenshotImageFormat.Png);
         var file = new FileInfo(filename);
         return(file);
     }
     catch (OpenQA.Selenium.WebDriverException we)
         when(we.IsWindowClosedException())
         {
             return(null);
         }
     catch (Exception exception)
     {
         throw;
     }
 }
Пример #13
0
        public void Test_15_Screenshot()
        {
            Screenshot sessionshot = session.GetScreenshot();

            Assert.IsNotNull(sessionshot);

            // Save Session ScreenShot to ImageFile
            sessionshot.SaveAsFile("/SessionScreenShot.png", ImageFormat.Png);
            // Get Session ScreenShot Base64EncodingString
            String base64str = sessionshot.AsBase64EncodedString;

            WindowsElement element     = session.FindElementByAccessibilityId("mainframe.ChildFrame00.form.TextArea00");
            Screenshot     elementshot = element.GetScreenshot();

            Assert.IsNotNull(elementshot);

            // Save Element ScreenShot to ImageFile
            elementshot.SaveAsFile("/ElementScreenShot.png", ImageFormat.Png);
            // Get Element ScreenShot Base64EncodingString
            String base64strelement = elementshot.AsBase64EncodedString;
        }
Пример #14
0
        public void TestMethod11()
        {
            var notepad = @"C:\Windows\System32\notepad.exe";

            var options = new AppiumOptions();

            options.AddAdditionalCapability("app", notepad);

            var driver = new WindowsDriver <WindowsElement>(new Uri(" http://127.0.0.1:4723/"), options);

            driver.Manage().Window.Maximize();

            var textEditor = driver.FindElementByAccessibilityId("15");

            textEditor.SendKeys("ABCDEF");

            var eyes = new Eyes();

            eyes.ApiKey = "lFMnO9e1nbFQEdhebrDmhEBOqB7jXUXJGogj103lRWAzM110";
            eyes.SetAppEnvironment("Windows 10", null);

            try
            {
                eyes.Open("AppiumPractice", "TestMethod11");
                Thread.Sleep(3000);
                var currentAppScreenshot = driver.GetScreenshot();
                var croppedScreenshot    = CropScreenshotWithRect(currentAppScreenshot, textEditor);
                var croppedScreenshot2   = CropScreenshotOf2(croppedScreenshot, new Rectangle(900, 0, textEditor.Size.Width - 900, textEditor.Size.Height));

                eyes.CheckImage(croppedScreenshot2, "Cropped Text Editor");

                eyes.Close();
            }
            finally
            {
                eyes?.AbortIfNotClosed();
                driver.Quit();
            }
        }
 /// <summary>
 /// Shot the session part screen and save it with full file name
 /// </summary>
 /// <param name="session">Session you want to shot</param>
 /// <param name="fullFileName">File name for image</param>
 public static void ShotScreen(WindowsDriver <WindowsElement> session, string fullFileName)
 {
     session.GetScreenshot().SaveAsFile(fullFileName, ScreenshotImageFormat.Png);
 }
Пример #16
0
        public void TestMLL()
        {
            // You can find the Application Id of your application in the generated AppX\vs.appxrecipe file under RegisteredUserModeAppID node. E.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App
            DesiredCapabilities appCapabilities = new DesiredCapabilities();

            appCapabilities.SetCapability("app", "1c0748ac-ce4c-4925-a3d3-e8cbd8d20db6_j0c0e5hxdtz1g!App");
            appCapabilities.SetCapability("deviceName", "Windows"); // Notwendig bei Start über Appium, nicht notwendig bei WinAppDriver.exe

            // Appium: http://127.0.0.1:4723/wd/hub
            // WinAppDriver.exe: http://127.0.0.1:4723
            using (var app = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities))
            {
                app.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0.0);

                Assert.IsNotNull(app);
                Assert.IsNotNull(app.SessionId);

                var text1 = "Dies ist eine Aufgabe";
                var text2 = "Dies ist noch eine Aufgabe";
                // Use the session to control the app
                app.FindElementByName("Remove all").Click();

                var sc = app.GetScreenshot();
                sc.SaveAsFile("Screen1.png");

                app.FindElementByAccessibilityId("C_Task").Click();

                app.FindElementByAccessibilityId("C_Datum").Click();

                var Feb = app.FindElementByAccessibilityId("HeaderButton");
                Feb.Click();
                var Maerz = app.FindElementByName("März");
                Maerz.Click();
                var eins = app.FindElementByName("1");
                eins.Click();
                //app.FindElementByAccessibilityId("C_Datum").Click();

                app.FindElementByAccessibilityId("C_Task").SendKeys(text1);

                // https://github.com/Microsoft/WinAppDriver/blob/master/Tests/UWPControls/DatePicker.cs


                app.FindElementByName("Add").Click();

                app.FindElementByAccessibilityId("C_Task").SendKeys(text2);
                app.FindElementByName("Add").Click();

                var listenelemente = app.FindElements(By.XPath($"//ListItem"));
                Assert.AreEqual(2, listenelemente.Count);
                var e = listenelemente[0];
                Assert.AreEqual(e.Text, "EFC_UWP.DAL.Task");
                // app.FindElements(By.XPath($"//Button"))

                string b = app.FindElementByAccessibilityId("C_Details").Text;
                //Assert.AreEqual(System.DateTime.Now.ToShortDateString() + ": " + text1, b);
                Assert.AreEqual("01.03." + System.DateTime.Now.Year + ": " + text1, b);
                var alleAufgaben = app.FindElements(By.XPath($"//*[contains(@Name, \"Aufgabe\")]"));
                Assert.IsTrue(alleAufgaben[0].Text.Contains(text1));
                Assert.IsTrue(alleAufgaben[1].Text.Contains(text2));

                // geht so nicht, weil die Liste sich durch "Done" verändert
                //var alleAufgabenDoneButtons = app.FindElements(By.XPath($"//*[contains(@Name, \"Done\")]"));
                //foreach (var done in alleAufgabenDoneButtons.Reverse().ToList())
                //{
                // done.Click();
                //}

                ReadOnlyCollection <WindowsElement> alleAufgabenDoneButtons;
                do
                {
                    alleAufgabenDoneButtons = app.FindElements(By.XPath($"//*[contains(@Name, \"Done\")]"));
                    alleAufgabenDoneButtons[0].Click();
                } while (alleAufgabenDoneButtons.Count > 1);


                var listenelemente2 = app.FindElements(By.XPath($"//ListItem"));
                Assert.AreEqual(0, listenelemente2.Count);

                app.CloseApp();
            }
        }
Пример #17
0
        public void GetScreenshot()
        {
            WindowsDriver <WindowsElement> notepadSession = null;
            WindowsDriver <WindowsElement> desktopSession = null;

            try
            {
                // Launch and capture a screenshot of a maximized Notepad application. The steps below intentionally use
                // the Notepad application window to fully cover the Alarms & Clock application. This setup demonstrates
                // that capturing Alarms & Clock screenshot afterward will implicitly bring its window to foreground.
                notepadSession = Utility.CreateNewSession(CommonTestSettings.NotepadAppId);
                notepadSession.Manage().Window.Maximize();
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
                OpenQA.Selenium.Screenshot notepadScreenshot = notepadSession.GetScreenshot();

                // Capture a screenshot of Alarms & Clock application
                // This implicitly brings the application window to foreground
                OpenQA.Selenium.Screenshot alarmsClockScreenshot = session.GetScreenshot();

                // Save the application screenshot capture locally on the machine running the test
                alarmsClockScreenshot.SaveAsFile(@"ScreenshotAlarmsClockApplication.png", ScreenshotImageFormat.Png);

                // Capture the entire desktop using the Desktop session
                desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId);
                OpenQA.Selenium.Screenshot desktopScreenshot = desktopSession.GetScreenshot();

                // Save the desktop screenshot capture locally on the machine running the test
                desktopScreenshot.SaveAsFile(@"ScreenshotDesktop.png", ScreenshotImageFormat.Png);

                using (MemoryStream msScreenshot1 = new MemoryStream(alarmsClockScreenshot.AsByteArray))
                    using (MemoryStream msScreenshot2 = new MemoryStream(notepadScreenshot.AsByteArray))
                        using (MemoryStream msScreenshot3 = new MemoryStream(desktopScreenshot.AsByteArray))
                        {
                            // Verify that the Alarms & Clock application screenshot has a valid size
                            Image screenshotImage1 = Image.FromStream(msScreenshot1);
                            Assert.AreEqual(session.Manage().Window.Size.Height, screenshotImage1.Height);
                            Assert.AreEqual(session.Manage().Window.Size.Width, screenshotImage1.Width);

                            // Verify that the maximized Notepad application screenshot has a valid size
                            Image screenshotImage2 = Image.FromStream(msScreenshot2);
                            Assert.AreEqual(notepadSession.Manage().Window.Size.Height, screenshotImage2.Height);
                            Assert.AreEqual(notepadSession.Manage().Window.Size.Width, screenshotImage2.Width);

                            // Verify that the application screenshot is smaller in size compared to the entire desktop
                            Image screenshotImage3 = Image.FromStream(msScreenshot3);
                            Assert.IsTrue(screenshotImage2.Height >= screenshotImage1.Height);
                            Assert.IsTrue(screenshotImage2.Width >= screenshotImage1.Width);
                        }
            }
            finally
            {
                if (notepadSession != null)
                {
                    notepadSession.Quit();
                }

                if (desktopSession != null)
                {
                    desktopSession.Quit();
                }
            }
        }
Пример #18
0
        private void runTestBtn_Click(object sender, EventArgs e)
        {
            var processDriver = Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
            var repoPath      = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName;

            AppiumOptions appiumOptions = new AppiumOptions();

            appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
            appiumOptions.AddAdditionalCapability("app", $@"{repoPath}\bin\Debug\Lab1.exe");

            WindowsDriver <WindowsElement> fileManagerApp;

            fileManagerApp = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions);

            fileManagerApp.FindElementByName("Load from text file").Click();

            Thread.Sleep(1000);

            SendKeys.SendWait($@"{repoPath}\Data.txt");

            SendKeys.SendWait("{ENTER}");

            Thread.Sleep(1000);

            foreach (Control c in this.Controls)
            {
                string[] skipCols = { "ID", "ManufacturerCountTxt" };

                if (c.GetType().Name == "TextBox" && !skipCols.Contains(c.Name) && c.Text != String.Empty)
                {
                    var cellName = $"{c.Name} Row {Int32.Parse(ID.Text) - 1}";

                    var cell = fileManagerApp.FindElementByName(cellName);

                    cell.Click();

                    cell.SendKeys(c.Text);
                }
            }

            if (ManufacturerCountTxt.Text != String.Empty)
            {
                fileManagerApp.FindElementByAccessibilityId("mfrTxt").SendKeys(ManufacturerCountTxt.Text);

                SendKeys.SendWait("{ENTER}");

                Thread.Sleep(500);

                fileManagerApp.GetScreenshot().SaveAsFile($@"{repoPath}\Screenshots\Manufacturers count.png");
            }

            foreach (var item in featuresList.CheckedItems)
            {
                fileManagerApp.FindElementByName(item.ToString()).Click();
            }

            if (featuresList.CheckedItems.Count > 0)
            {
                fileManagerApp.FindElementByName("Export from grid to XML").Click();

                Thread.Sleep(1000);

                SendKeys.SendWait($@"{repoPath}\RobotExportedXML.xml");

                Thread.Sleep(1000);

                SendKeys.SendWait("{ENTER}");
                SendKeys.SendWait("{ENTER}");
            }

            Thread.Sleep(1000);

            fileManagerApp.GetScreenshot().SaveAsFile($@"{repoPath}\Screenshots\Export.png");

            Process.Start("notepad++.exe", $@"{repoPath}\RobotExportedXML.xml");

            Thread.Sleep(2000);

            Process.Start($@"{repoPath}\Screenshots\Manufacturers count.png");
            Thread.Sleep(1000);
            SendKeys.SendWait("{ENTER}");

            Thread.Sleep(3000);

            Process.Start($@"{repoPath}\Screenshots\Export.png");
            Thread.Sleep(1000);
            SendKeys.SendWait("{ENTER}");
        }
Пример #19
0
        //滑動skype右方欄位,並截取所有聊天室的對話圖片
        public bool autoScrollScreenShotOnePage(string folderPath, int side, int num)
        //folderPath為儲存路徑;side為滑動方向 0為up 1為down;num代表要截圖的數量,可以先設定MAX再讓系統判斷
        {
            WindowsElement ContentScrollViewer = null;
            XElement       ContentScrollBar    = null;


            //如果要截圖的數量大於0
            while (num-- > 0)
            {
                try
                {
                    //先找ScrollViewer[1]對話框 = 右邊的聊天室 ScrollViewer是skype裏面設定的名稱
                    var ScrollViewerElements = session.FindElementsByClassName("ScrollViewer");
                    //如沒找到對話框,可能是使用者把界面關掉了
                    if (ScrollViewerElements.Count == 0)
                    {
                        throw new ArgumentException("Can't Find View");
                    }

                    //將設定聊天室元件變數
                    ContentScrollViewer = ScrollViewerElements[1];

                    //PageSource為該頁面的内容: xml
                    string source = session.PageSource;

                    //讀取該頁面的XML
                    XDocument doc = XDocument.Parse(session.PageSource);

                    //將ScrollViewer元件的XML讀取出來
                    var xmlScrollViewerElements = doc.Descendants()
                                                  .Where(x =>
                                                         x.Attribute("ClassName").Value == "ScrollViewer");

                    //將滑動杆的XML讀取出來
                    var xmlContentScrollBarElements = doc.Descendants()
                                                      .Where(x =>
                                                             x.Attribute("ClassName").Value == "ScrollBar");

                    //先判斷xmlScrollViewerElements是、 是可以垂直滑動的
                    if (xmlScrollViewerElements.ElementAt(1).Attribute("VerticallyScrollable").Value == "True")
                    {
                        if (xmlScrollViewerElements.ElementAt(0).Attribute("VerticallyScrollable").Value == "False")
                        {
                            ContentScrollBar = xmlContentScrollBarElements.ElementAt(0);
                        }
                        else
                        {
                            ContentScrollBar = xmlContentScrollBarElements.ElementAt(1);
                        }
                    }

                    //將原件對應到聊天框的element
                    var matchingElements = doc.Descendants()
                                           .Where(x =>
                                                  x.Attribute("Name").Value != "" &&
                                                  x.Attribute("y").Value != "0" &&
                                                  x.Attribute("ClassName").Value != "TextBlock" &&
                                                  x.Attribute("ClassName").Value != "RichTextBlock" &&
                                                  x.Attribute("LocalizedControlType").Value == "group");

                    //設定filename
                    string filename = DateTime.Now.Month.ToString() + "-" +
                                      DateTime.Now.Day.ToString() + "-" +
                                      DateTime.Now.Hour.ToString() + "-" +
                                      DateTime.Now.Minute.ToString() + "-" +
                                      DateTime.Now.Second.ToString() + "-" +
                                      DateTime.Now.Millisecond.ToString();

                    //產生截圖並儲存
                    Console.WriteLine("Getting Picture ... " + filename);
                    //使用WinDriver將畫面截圖保存
                    session.GetScreenshot().SaveAsFile(folderPath + "\\" + filename + ".png", ScreenshotImageFormat.Png);

                    //產生文字檔並儲存
                    Console.WriteLine("Processing Text ... " + filename);
                    StreamWriter sw = File.CreateText(folderPath + "\\" + filename + ".txt");
                    //將所有xml文字寫入檔案
                    foreach (var element in matchingElements)
                    {
                        sw.WriteLine(element.Attribute("Name").Value);
                    }
                    sw.Close();


                    //如果不能滑動則停止function
                    if (null == ContentScrollBar)

                    {
                        break;
                    }

                    //如果可以滑動,則將聊天框往上滑,0的屬性代表往上滑
                    if (0 == side)
                    {
                        ContentScrollViewer.SendKeys(Keys.PageUp);
                        //value= 0代表滑到頂,則停止程式執行
                        if (ContentScrollBar.Attribute("Value").Value == "0")
                        {
                            break;
                        }
                    }
                    else
                    {
                        //若爲1,則執行往下滑
                        ContentScrollViewer.SendKeys(Keys.PageDown);
                        if (Math.Abs(double.Parse(ContentScrollBar.Attribute("Maximum").Value) - double.Parse(ContentScrollBar.Attribute("Value").Value)) < 10)
                        {
                            break;
                        }
                    }
                }
                catch
                {
                    Thread.Sleep(1000);
                    continue;
                }
            }
            //滑倒低,則將程式完成
            Console.WriteLine("Complete");
            return(true);
        }