public static IWebElement waitElementExistsByXpath(String Xpath)
        {
            (
                new WebDriverWait(driver, TimeSpan.FromSeconds(30))).Until(ExpectedConditions.ElementExists(By.XPath(Xpath)));
            IWebElement element = driver.FindElement(By.XPath(Xpath));;

            return(element);
        }
        public bool FluentWait(string obj, int timeoutInSeconds)
        {
            if (timeoutInSeconds > 0)
            {
                var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(timeoutInSeconds));
                var test = wait.Until(ExpectedConditions.ElementExists(By.XPath(obj)));

                // if (wait.Until(drv => drv.FindElement(By.XPath(obj))) != null)
                if (test != null)
                {
                    return(true);
                }
            }

            return(true);;
        }
示例#3
0
 public IList <IWebElement> FindElements(By by, int i = 5, bool exist = false)
 {
     try
     {
         if (exist)
         {
             Sleep(i * 500); return(driver.FindElements(by));
         }
         Wait(ExpectedConditions.ElementExists(by), i);
         return(driver.FindElements(by));
     }
     catch (StaleElementReferenceException ex)
     {
         return(FindElements(by));
     }
     catch (NoSuchElementException e)
     {
         return(null);
     }
 }
示例#4
0
        public IWebElement FindElement(By by)
        {
            IWebElement el = DriverWait.Until(ExpectedConditions.ElementExists(by));

            return(el);
        }
示例#5
0
 public static void waitForElement(By elem)
 {
     wait.Until(ExpectedConditions.ElementExists(elem));
     Trace.WriteLine("Dynamicallay waited for Element " + elemdesc);
 }
示例#6
0
        public void TestMethod()
        {
            //using Chrome as browser
            IWebDriver driver = new ChromeDriver();

            //go to Orange HRM
            driver.Url = "https://opensource-demo.orangehrmlive.com";


            //Login
            IWebElement elementUsername = driver.FindElement(By.Id("txtUsername"));

            elementUsername.SendKeys("admin");
            IWebElement elementPassword = driver.FindElement(By.Id("txtPassword"));

            elementPassword.SendKeys("admin123");
            IWebElement elementLogin = driver.FindElement(By.Name("Submit"));

            elementLogin.Click();

            //User Management via Admin tab
            IWebElement elementAdmin = driver.FindElement(By.Id("menu_admin_viewAdminModule"));

            elementAdmin.Click();

            //Filling the search data
            //Username
            IWebElement elementUsernameSystem = driver.FindElement(By.Id("searchSystemUser_userName"));

            elementUsernameSystem.SendKeys("admin");

            //User Role
            IWebElement selectDropDownListUserRole = driver.FindElement(By.Id("searchSystemUser_userType"));

            new SelectElement(selectDropDownListUserRole).SelectByValue("1");

            //Search
            IWebElement elementSearch = driver.FindElement(By.Id("searchBtn"));

            elementSearch.Click();

            //Reset
            IWebElement elementReset = driver.FindElement(By.Id("resetBtn"));

            elementReset.Click();

            //Add User
            IWebElement elementAdd = driver.FindElement(By.Name("btnAdd"));

            elementAdd.Click();

            //Add user
            //Role
            Thread.Sleep(1000);
            IWebElement selectDropDownListAddRole = driver.FindElement(By.Id("systemUser_userType"));

            new SelectElement(selectDropDownListAddRole).SelectByValue("2");

            //Name
            Thread.Sleep(1000);
            IWebElement elementAddName = driver.FindElement(By.Id("systemUser_employeeName_empName"));

            elementAddName.SendKeys("lahanta");
            Thread.Sleep(1000);
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));

            wait.Until(ExpectedConditions.ElementExists(By.ClassName("ac_results")));

            IWebElement elementlist = driver.FindElement(By.ClassName("ac_results"));

            elementlist.Click();

            //Username
            IWebElement elementAddSystemUserName = driver.FindElement(By.Id("systemUser_userName"));

            elementAddSystemUserName.SendKeys("lahanta.smith");

            //Password
            IWebElement elementAddSystemPassword = driver.FindElement(By.Id("systemUser_password"));

            elementAddSystemPassword.SendKeys("P@ssw0rd1===");

            //Confirm Password
            IWebElement elementAddSystemConfirmPassword = driver.FindElement(By.Id("systemUser_confirmPassword"));

            elementAddSystemConfirmPassword.SendKeys("P@ssw0rd1===");

            //Try to cancel
            //Thread.Sleep(1000);
            //IWebElement elementCancel = driver.FindElement(By.Id("btnCancel"));
            //elementCancel.Click();


            //Save button
            Thread.Sleep(1000);
            IWebElement elementSave = driver.FindElement(By.Id("btnSave"));

            elementSave.Click();

            Thread.Sleep(2000);

            //Close the browser
            driver.Close();
        }