Beispiel #1
0
 public override WindowsElement FindElement(WindowsDriver <WindowsElement> searchContext)
 {
     return(searchContext.FindElementById(Value));
 }
Beispiel #2
0
        private string GetContactName()
        {
            var control = _session.FindElementById(_contactControlId);

            return(control.Displayed ? control.Text : null);
        }
Beispiel #3
0
        //點擊所有聯絡人
        public bool autoClickContactPersonScrollScreenShotEachPage(string folderPath, int folderName)
        {
            XDocument      doc = null;
            WindowsElement ContactPersonScrollViewer = null;

            while (true)
            {
                try
                {
                    //先找到左邊聯絡人欄位
                    var ScrollViewerElements = session.FindElementsByClassName("ScrollViewer"); //尋找兩個下拉框
                    //如果沒有找到任何欄位,表示程式沒有完整開啓
                    if (ScrollViewerElements.Count == 0)
                    {
                        throw new ArgumentException("Can't Find View");
                    }

                    doc = XDocument.Parse(session.PageSource); //PageSource取得XML結構  XDocument C#提供API

                    //將掃描到的XML中Scrollviweer相關的資訊放到XML element中
                    var xmlScrollViewerElements = doc.Descendants()
                                                  .Where(x =>
                                                         x.Attribute("ClassName").Value == "ScrollViewer");

                    //確認滑動杆可不可以上下滑動
                    if (xmlScrollViewerElements.ElementAt(0).Attribute("VerticallyScrollable").Value == "True")
                    {
                        //可以的話就設定聯絡人部分滑動杆的變數
                        ContactPersonScrollViewer = ScrollViewerElements[0];
                    }

                    if (ContactPersonScrollViewer != null)
                    {
                        while (true)
                        {
                            //將滑動杆的XML資訊存爲變數
                            var ScrollBarElements = doc.Descendants()
                                                    .Where(x =>
                                                           x.Attribute("ClassName").Value == "ScrollBar");


                            //透過檢查ScrollBarElements的Value是否為0來確認是否滑倒頂
                            if (double.Parse(ScrollBarElements.ElementAt(0).Attribute("Value").Value) != 0)
                            {
                                ContactPersonScrollViewer.SendKeys(Keys.PageUp);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    break;
                }
                catch
                {
                    Thread.Sleep(1000);
                    continue;
                }
            }

            //建立hashtable資料結構,將已點擊過的聯絡人資訊儲存在hashtable的資料結構
            HashSet <string> AlreadlyClickID = new HashSet <string>();

            while (true)
            {
                try
                {
                    if (session.FindElementsByClassName("ScrollViewer").Count == 0)
                    {
                        throw new ArgumentException("Can't Find View");
                    }


                    //將頁面的XML資訊存到doc變數
                    doc = XDocument.Parse(session.PageSource);

                    //source變數儲存原始頁面資訊
                    string source = session.PageSource;

                    //取得所有聯絡人頭像元件
                    var matchingElements = doc.Descendants()
                                           .Where(x =>
                                                  x.Attribute("Name").Value != "" &&
                                                  x.Attribute("x").Value == "0" &&
                                                  x.Attribute("y").Value != "0" &&
                                                  x.Attribute("LocalizedControlType").Value == "button" &&
                                                  x.Attribute("IsKeyboardFocusable").Value == "False");

                    //變例所有元件
                    foreach (var element in matchingElements)
                    {
                        //取得該元件的的RuntimeId
                        string ID = element.Attribute("RuntimeId").Value;
                        //先確認RuntimeId是否已經被點擊過,若沒被點擊過,先把他加到HASHTABLE
                        if (AlreadlyClickID.Add(ID))
                        {
                            while (true)
                            {
                                try
                                {
                                    //點擊RuntimeId,就可以點解聯絡人
                                    var clickElement = session.FindElementById(ID);
                                    clickElement.Click();
                                    clickElement.Click();
                                    break;
                                }
                                catch
                                {
                                    Thread.Sleep(1000);
                                    continue;
                                }
                            }

                            //最後先建立文件檔案
                            Directory.CreateDirectory(folderPath + "\\" + Convert.ToString(folderName));
                            //執行該聯絡人的聊天室截圖
                            autoScrollScreenShotOnePage(folderPath + "\\" + Convert.ToString(folderName), 0, Int32.MaxValue);
                            folderName++;
                        }
                    }
                }
                catch
                {
                    Thread.Sleep(1000);
                    continue;
                }

                if (null == ContactPersonScrollViewer)
                {
                    break;
                }

                while (true)
                {
                    try
                    {
                        doc = XDocument.Parse(session.PageSource);

                        var ScrollBarElements = doc.Descendants()
                                                .Where(x =>
                                                       x.Attribute("ClassName").Value == "ScrollBar");

                        if (ScrollBarElements.ElementAt(0).Attribute("Value").Value == ScrollBarElements.ElementAt(0).Attribute("Maximum").Value)
                        {
                            return(true);
                        }
                        else
                        {
                            ContactPersonScrollViewer.SendKeys(Keys.PageDown);
                        }
                        break;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            return(true);
        }