示例#1
0
        static public void AlertYesOrNo(IWebDriver driver, string Message, string Judge)
        {
            if (!JWait.WaitUntil(() =>
            {
                IAlert a = driver.SwitchTo().Alert();
                if (a.Text.Contains(Message))
                {
                    switch (Judge)
                    {
                    case "确定":
                        a.Accept();
                        break;

                    case "取消":
                        a.Dismiss();
                        break;

                    default:
                        throw new Exception(string.Format("✘:核对{0}参数是否填写正确", Judge));
                    }
                }
                else
                {
                    throw new Exception(string.Format("✘:核对{0}文本内容", Message));
                }
            }, 30))
            {
                throw new Exception("✘:未找到弹出框");
            }
        }
示例#2
0
        public static IWebElement GetFileInputElement(IWebDriver driver, string Tvalue, string Target)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            string sXpath = JXpath.FileInput(Target, Tvalue);

            return(element = driver.FindElement(By.XPath(sXpath)));
        }
示例#3
0
        public static IWebElement GetDateTimeElement(IWebDriver driver, string Target, string Tvalue, string sType)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            string sXpath = JXpath.DateTimeInput(Target, Tvalue, sType);

            return(element = JFind.XPath(driver, sXpath));
        }
示例#4
0
        public static IWebElement GetSelectElement(IWebDriver driver, string Tvalue, string Target)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            string sXpath = JXpath.Select(Target, Tvalue);

            return(element = JFind.XPath(driver, sXpath));
        }
示例#5
0
        public static IWebElement GetDirectionElement(IWebDriver driver, string Tvalue)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            string sXpath = JXpath.DirectionButton(Tvalue);

            return(element = JFind.XPath(driver, sXpath));
        }
示例#6
0
        public static IWebElement GetValidXpath(IWebDriver driver, string Tvalue, string Target)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            string sXpath = JXpath.Valid(Tvalue, Target);

            return(element = JFind.XPath(driver, sXpath));
        }
示例#7
0
 static public void Clear(IWebElement element)
 {
     if (!JWait.WaitUntil(() =>
     {
         element.Clear();
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】清空失败", element));
     }
 }
示例#8
0
 static public void SendKeys(IWebElement element, string Tvalue)
 {
     if (!JWait.WaitUntil(() =>
     {
         element.SendKeys(Tvalue);
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】输入失败", element));
     }
 }
示例#9
0
 static public void ValidAlert(IWebDriver driver, string Message)
 {
     JWait.WaitUntil(() => {
         IAlert a = driver.SwitchTo().Alert();
         if (!a.Text.Equals(Message))
         {
             throw new Exception(string.Format("✘:弹出框文本验证失败"));
         }
     });
 }
示例#10
0
 static public void DoubleClick(IWebDriver driver, IWebElement element)
 {
     if (!JWait.WaitUntil(() =>
     {
         Actions builder = new Actions(driver);
         builder.DoubleClick(element).Perform();
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】双击失败", element));
     }
 }
示例#11
0
 static public void EnterAction(IWebDriver driver, IWebElement element)
 {
     if (!JWait.WaitUntil(() =>
     {
         Actions builder = new Actions(driver);
         builder.SendKeys(Keys.Enter).Perform();
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】回车失败", element.Text));
     }
 }
示例#12
0
 static public IWebElement ID(IWebDriver driver, string ID)
 {
     if (!JWait.WaitUntil(() =>
     {
         element = driver.FindElement(By.Id(ID));
     }, 10))
     {
         throw new NoSuchElementException(string.Format("✘:【{0}】ID错误,找不到元素", ID));
     }
     return(element);
 }
示例#13
0
 static public void MoveToElement(IWebDriver driver, IWebElement element)
 {
     if (!JWait.WaitUntil(() =>
     {
         Actions builder = new Actions(driver);
         builder.MoveToElement(element).Perform();
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】移动至该元素失败,当前页面可能存在重复项,请核对", element.Text));
     }
 }
示例#14
0
 static public void ClickJS(IWebDriver driver, IWebElement element)
 {
     if (!JWait.WaitUntil(() =>
     {
         IJavaScriptExecutor js = ((IJavaScriptExecutor)driver);
         js.ExecuteScript("arguments[0].click()", element);
     }, 30))
     {
         throw new Exception(string.Format("✘:【{0}】点击失败,当前页面可能存在重复项,请核对", element.Text));
     }
 }
示例#15
0
 static public IWebElement ClassName(IWebDriver driver, string ClassName)
 {
     if (!JWait.WaitUntil(() =>
     {
         elements = driver.FindElements(By.ClassName(ClassName)).Where(x => x.Displayed && x.Enabled).ToList();
         if (elements.Count < 1)
         {
             throw new NoSuchElementException();
         }
     }, 10))
     {
         throw new NoSuchElementException(string.Format("✘:【{0}】ClassName错误,找不到元素", ClassName));
     }
     return(elements[0]);
 }
示例#16
0
 static public IList <IWebElement> XPaths(IWebDriver driver, string Xpathstring)
 {
     if (!JWait.WaitUntil(() =>
     {
         elements = driver.FindElements(By.XPath(Xpathstring)).Where(x => x.Displayed && x.Enabled).ToList();
         if (elements.Count < 1)
         {
             throw new NoSuchElementException();
         }
     }, 10))
     {
         throw new NoSuchElementException(string.Format("✘:【{0}】语句错误,找不到元素", Xpathstring));
     }
     return(elements);
 }
示例#17
0
        public static void SwitchToPageNum(IWebDriver driver, string Tvalue)
        {
            JWait.WaitForAjaxComplete(driver, 30);
            elements = driver.FindElements(By.ClassName("page-num"));
            if (Tvalue.Contains("尾页"))
            {
                List <string> pageNumb = new List <string>();
                foreach (IWebElement item in elements)
                {
                    pageNumb.Add(item.Text);
                }
                Tvalue = pageNumb.Max();
            }
            IJavaScriptExecutor js = ((IJavaScriptExecutor)driver);

            js.ExecuteScript(string.Format("javascript:gotoPage({0})", Tvalue));
        }
示例#18
0
 static public bool IsElementExist(IWebDriver driver, By locator, int?Time = 10)
 {
     try
     {
         if (!JWait.WaitUntil(() =>
         {
             driver.FindElement(locator);
         }, Time.Value))
         {
             throw new Exception("✘:未找到元素");
         }
         return(true);
     }
     catch
     {
         //Element is not exsit, we don't do anything
         return(false);
     }
 }
示例#19
0
 static public void Click(IWebElement ele)
 {
     if (!JWait.WaitUntil(() =>
     {
         element = ele;
         element.Click();
     }, 30))
     {
         //Develop Model
         //if (DataStatus.DevelopeModel)
         //{
         //    WebUI.WclForm_Element(element, "元素点击失败");
         //    element.Click();
         //}
         //else
         //{
         throw new Exception(string.Format("✘:【{0}】点击失败,当前页面可能存在重复项,请核对", element.Text));
         //}
     }
 }
示例#20
0
 static public IWebElement XPath(IWebDriver driver, string Xpathstring)
 {
     if (!JWait.WaitUntil(() =>
     {
         elements = driver.FindElements(By.XPath(Xpathstring)).Where(x => x.Displayed && x.Enabled).ToList();
         if (elements.Count < 1)
         {
             throw new NoSuchElementException();
         }
     }, 10))
     {
         //Develop Model Set
         //if (DataStatus.DevelopeModel)
         //{
         //    WebUI.WclForm_Xpath(Xpathstring);
         //}
         //else {
         throw new NoSuchElementException(string.Format("✘:找不到元素,请检查参数是否填写正确,xpath:{0}", Xpathstring));
         //}
     }
     return(elements[0]);
 }