public void SearchStudent(string People)
        {
            var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(PropertiesCollection.driver, TimeSpan.FromSeconds(60));

            System.Threading.Thread.Sleep(60000);
            PropertiesCollection.driver.SwitchTo().Frame("myFrame");
            System.Threading.Thread.Sleep(2000);

            wait.Until(ExpectedConditions.ElementToBeClickable(btnPeopleSelector));
            btnPeopleSelector.Click();
            System.Threading.Thread.Sleep(2000);
            wait.Until(ExpectedConditions.ElementToBeClickable(txtPeopleSelector));
            txtPeopleSelector.Click();

            txtPeopleSelector.SendKeys(People);
            wait.Until(ExpectedConditions.ElementToBeClickable(btnPeopleSearch));

            btnPeopleSearch.Click();
            System.Threading.Thread.Sleep(5000);

            firstgrdPeopleSelector.Click();

            wait.Until(ExpectedConditions.ElementToBeClickable(btnApply));
            btnApply.Click();
        }
Ejemplo n.º 2
0
        private void AcessarTelaSolicitarMigracao()
        {
            const string Url = "//*[@id=\"1\"]/ul/li/a[@href=\"paginas/filiado/SolicitaMigracao.aspx\"]";

            navegador.FindElement(By.XPath("//*[@id=\"1\"]/h3")).Click();
            wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(Url)));
            navegador.FindElement(By.XPath(Url)).Click();
        }
Ejemplo n.º 3
0
        protected IWebElement WaitForElementByTime(By locator, TimeSpan time)
        {
            WaitUntilPageReady();
            OpenQA.Selenium.Support.UI.WebDriverWait waitTime = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, time);
            waitTime.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(locator));
            IWebElement element = driver.FindElement(locator);

            waitTime.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(element));
            return(element);
        }
Ejemplo n.º 4
0
        public void ConfigurarLogin(string _login, string _senha)
        {
            SetLogin(_login);
            SetSenha(_senha);

            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("txbLogin")));

            navegador.FindElement(By.Id("txbLogin")).SendKeys(_login);
            navegador.FindElement(By.Id("txbSenha")).SendKeys(_senha + Keys.Enter);
        }
        protected IWebElement WaitForElementByTime(By locator, int seconds)
        {
            WaitUntilPageReady();
            OpenQA.Selenium.Support.UI.WebDriverWait waitTime = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
            waitTime.Until(ExpectedConditions.ElementExists(locator));
            IWebElement element = driver.FindElement(locator);

            waitTime.Until(ExpectedConditions.ElementToBeClickable(element));
            return(element);
        }
Ejemplo n.º 6
0
 public (IWebElement, string) LocalizarDocumentoPorClass(string documento, string nomeClass, string idTabelaMigracao)
 {
     try
     {
         var xPath = "//*[@id=" + idTabelaMigracao + "]/tbody/tr[@class=" + nomeClass + "]";
         wait.Until(ExpectedConditions.ElementExists(By.XPath(xPath)));
         return(navegador.FindElements(By.XPath(xPath)).Where(m => m.Text.Contains(documento)).FirstOrDefault(), nomeClass);
     }
     catch
     {
         return(null, null);
     }
 }
Ejemplo n.º 7
0
        public void What_Is_Implicit_Wait_And_Explicit_Wait()
        {
            //Implicit wait- Asking the browser to wait for amount of time driver should wait while searching for an element if it is not present immediately
            //If the element is found beofre the time seciified the next step will be executed without waiting for remaining time mentioned in implicit wait.
            chromedriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            //Explicit Wait- Specific wait
            OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(chromedriver, TimeSpan.FromSeconds(10));
            wait.Message = "";                                       //Gets for sets the message to be displayed when time expires
            wait.IgnoreExceptionTypes();                             //Configures this instance to ignore the specific exceptions while waiting on the condition
            wait.PollingInterval = TimeSpan.FromMilliseconds(100);   //Gets or sets how often the condition should be evaluated. The deafult timeout is 500milliseond
            wait.Until(x => x.FindElements(By.XPath("")).Count > 1); //Condtion till the wait should be applied. Throws exception when timeout expires.
            //wait.Until(ExpectedConditions.)
            wait.Until(ExpectedConditions.AlertIsPresent());
            //An expectation for checking that an element is present on the DOM of a page
            //This does not necessarily mean that the element is visible.
            //// Returns:
            //     The OpenQA.Selenium.IWebElement once it is located.
            wait.Until(ExpectedConditions.ElementExists(By.Id("elem")));

            // Summary:
            //     An expectation for checking that an element is present on the DOM of a page and
            //     visible. Visibility means that the element is not only displayed but also has
            //     a height and width that is greater than 0.
            // Returns:
            //     The OpenQA.Selenium.IWebElement once it is located and visible.
            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("elem")));

            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("elem")));

            wait.Until(ExpectedConditions.TextToBePresentInElement(chromedriver.FindElement(By.Id("elem")), ""));
            // An expectation for checking the title of a page.
            wait.Until(ExpectedConditions.TitleIs(""));
            wait.Until(ExpectedConditions.UrlContains(""));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retries the wait for document loaded.
        /// </summary>
        private void _RetryWaitForDocumentLoaded()
        {
            IWebDriver         driver = Factory.Instance;
            IWait <IWebDriver> wait   = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(Browsers.DefaultTimeoutInSeconds));

            wait.Until(d => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
        }
Ejemplo n.º 9
0
        private void SearchResultPageScrollDown()
        {
            ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
            Logger.Debug($"Sleeping for {ri * 500} milliseconds for Ajax requests");
            Thread.Sleep(ri * 500);

            Logger.Debug("Scrolling down page...");

            IJavaScriptExecutor jse = (IJavaScriptExecutor)_driver;

            jse.ExecuteScript($"window.scrollBy(0,600)", "");


            jse.ExecuteScript($"window.scrollBy(0,600)", "");

            ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
            Logger.Debug($"Sleeping for {ri * 500} milliseconds for Ajax requests");
            Thread.Sleep(ri * 500);

            jse.ExecuteScript($"window.scrollBy(0,600)", "");

            ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
            Logger.Debug($"Sleeping for {ri * 500} milliseconds for Ajax requests");
            Thread.Sleep(ri * 500);

            jse.ExecuteScript($"window.scrollBy(0,-700)", "");

            ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
            Logger.Debug($"Sleeping for {ri * 500} milliseconds for Ajax requests");
            Thread.Sleep(ri * 500);

            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(_driver, TimeSpan.FromSeconds(15.00));

            wait.Until(wd => ((IJavaScriptExecutor)_driver).ExecuteScript("return document.readyState").ToString() == "complete");
        }
Ejemplo n.º 10
0
        private void PageScrolDown(int offset = 1300, bool applyRandomwait = true)
        {
            //wait for loading new emps
            if (applyRandomwait)
            {
                ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
                Thread.Sleep(ri * 100);
            }

            //scroll down to load the employees
            IJavaScriptExecutor jse = (IJavaScriptExecutor)_driver;

            jse.ExecuteScript($"window.scrollBy(0,{offset})", "");

            //wait for loading new emps
            if (applyRandomwait)
            {
                ri = r.Next(_settings.ScrollMinWait, _settings.ScrollMaxWait);
                Logger.Debug($"Sleeping for {ri * 500} milliseconds for Ajax requests");
                Thread.Sleep(ri * 500);
            }

            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(_driver, TimeSpan.FromSeconds(15.00));

            wait.Until(wd => ((IJavaScriptExecutor)_driver).ExecuteScript("return document.readyState").ToString() == "complete");
        }
Ejemplo n.º 11
0
 void WaitForLoad(IWebDriver driver, int timeoutSec)
 {
     while (true)
     {
         Thread.Sleep(1000);
         try
         {
             if (driver.Url != previousUrl)
             {
                 IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSec));
                 wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                 previousUrl = driver.Url;
                 //MessageBox.Show("Loaded");
                 int index = 0;
                 foreach (string item in listScripts)
                 {
                     string currentAddress = removeProtocol(readControlText(listViewScripts, index));
                     //MessageBox.Show(driver.Url + "\n" + currentAddress);
                     if (getControlChecked(listViewScripts, index) && removeProtocol(driver.Url).StartsWith(currentAddress))
                     {
                         string jsCode = listScripts[index].ToString();
                         //MessageBox.Show("Executing script");
                         IJavaScriptExecutor js = driver as IJavaScriptExecutor;
                         js.ExecuteScript(jsCode);
                     }
                     index++;
                 }
                 //MessageBox.Show("DOne");
             }
         }
         catch (Exception ee) { }
     }
 }
Ejemplo n.º 12
0
        /*    public IList<CCLISong> search(String term)
         *  {
         *      IList<CCLISong> list = new List<CCLISong>();
         *
         *      this.driver.Navigate().GoToUrl("https://olr.ccli.com/search/results?SearchTerm=" + Uri.EscapeUriString(term) + "&PageSize=100&AllowRedirect=False");
         *      this.wait();
         *      ICollection<IWebElement> elements = this.driver.FindElementById("searchResults").FindElements(By.TagName("td"));
         *
         *      foreach (var item in elements.Take(10))
         *      {
         *          var ViewSong = item.FindElement(By.ClassName("searchResultsSongSummary")).FindElement(By.ClassName("row"));
         *          var uuid = item.FindElement(By.ClassName("searchResultsSongSummary")).GetAttribute("id").Replace("song-", String.Empty);
         *          ViewSong.FindElement(By.TagName("a")).Click();
         *          this.wait();
         *          var dataModalId = ViewSong.FindElement(By.TagName("a")).GetAttribute("data-reveal-id");
         *          var detailsDiv = this.driver.FindElementById(dataModalId);
         *
         *          var title = detailsDiv.FindElement(By.TagName("h3")).Text;
         *          var ccliId = detailsDiv.FindElement(By.TagName("h4")).Text;
         *
         *          bool publicDomain = false;
         *          string unparsedAuthors = "";
         *          try
         *          {
         *              unparsedAuthors = detailsDiv.FindElements(By.ClassName("secondarySongAttributes"))[0].Text;
         *              publicDomain = detailsDiv.FindElements(By.ClassName("secondarySongAttributes"))[1].Text.Contains("Public Domain");
         *          }
         *          catch (Exception e)
         *          {
         *              // ignore
         *          }
         *
         *          detailsDiv.FindElement(By.ClassName("close-reveal-modal")).Click();
         *          this.wait();
         *
         *          var ReportSong = item.FindElement(By.ClassName("searchResultsSongSummary")).FindElement(By.ClassName("row"));
         *
         *          var song = new CCLISong(title, unparsedAuthors, ccliId, publicDomain);
         *          list.Add(song);
         *      }
         *      return list;
         *  }*/

        private void Wait()
        {
            IWait <OpenQA.Selenium.IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
        }
        public void WaitTillPageIsLoaded()
        {
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(webDriver, TimeSpan.FromSeconds(60.00));

            wait.Until(
                driver => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
        }
Ejemplo n.º 14
0
        public static void WaitforthePageLoad()
        {
            try
            {
                // driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(Constants.WaitforthePageLoad));

                IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(Constants.WaitforthePageLoad));



                wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
            }
            catch (Exception e)
            {
                Logger.error("Failed to load the Page", e);
                Test.Result("Page should be loaded", "Failed to Load the page", "Failed");
            }
            finally
            {
                Logger.info("  loading  the page" + "*--*--*--*");
                if (driver.Url.ToLower().Contains("error"))
                {
                    Test.Result("Logout should be successful", "Un expected error while performing logout", "Failed");
                    Test.TakeScreenShot();
                }
                // Logger.info("In" + PageName + "*-_-*-_-*-_-*" + ObjectName);
            }
        }
Ejemplo n.º 15
0
        public static void WaitForPageLoad(this IWebDriver driver)
        {
            var wait =
                new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
        }
Ejemplo n.º 16
0
        public string click(IWebDriver driver, List <filtry.unactiveFilters> lists, int number)
        {
            string filterName;

            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            if (number >= 0)
            {
                filterName = lists[number].textFilter.Text;
                lists[number].textFilter.Click();
                return(filterName);
            }
            else
            {
                number = rand.Next(0, lists.Count - 1);

                filterName = lists[number].textFilter.Text;

                ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", lists[number].textFilter);
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
                try
                {
                    lists[number].textFilter.Click();
                    wait.Until(ExpectedConditions.StalenessOf(lists[number].textFilter));
                    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
                }
                catch
                {
                    MessageBox.Show("Nie udało się kliknąć filtru");
                }
                return(filterName);
            }
        }
Ejemplo n.º 17
0
        public static void WaitForPageLoadNew(this IWebDriver webDriver, TimeSpan timeSpan)
        {
            Thread.Sleep(5000);
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(webDriver, timeSpan);

            wait.Until(driver1 => ((IJavaScriptExecutor)webDriver).ExecuteScript("return document.readyState").Equals("complete"));
        }
Ejemplo n.º 18
0
        public static void TryClick(this IWebDriver driver, By by)
        {
            var element             = driver.FindElement(by);
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(5.00));

            wait.Until(driver1 => driver.tryClick(by));
        }
Ejemplo n.º 19
0
        public List <PlayableElement> GetVideos()
        {
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            wait.Until(drive => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
            IReadOnlyCollection <IWebElement> elList;

            videos = new List <PlayableElement>();

            elList = driver.FindElements(By.ClassName(YouTubeValues.YTMainVideoLockup));
            if (elList.Count != 0)
            {
                foreach (IWebElement el in elList)
                {
                    if (el.Displayed)
                    {
                        VideoElementsSafeguardMainPage(() => { ListVideoMainPage(el); }, el);
                    }
                }
            }
            else
            {
                elList = driver.FindElements(By.XPath(string.Format(YouTubeValues.LiContainsVideo)));
                foreach (IWebElement el in elList)
                {
                    if (el.Displayed)
                    {
                        VideoElementsSafeguardSuggestionBar(() => { ListVideoSuggestionBar(el); }, el);
                    }
                }
            }
            return(videos);
        }
Ejemplo n.º 20
0
        ////public static bool IsStale(this IWebDriver webDriver, IWebElement webElement)
        ////{
        ////    return ExpectedConditions.StalenessOf(webElement)(webDriver);
        ////}



        public static System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> WaitForElements(this IWebDriver driver, string css, int time = 120)
        {
            OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(time));

            System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> pagelinks = null;
            try
            {
                pagelinks = wait.Until((d) =>
                {
                    return(d.FindElements(By.CssSelector(css)));
                });
            }
            catch
            {
                int cnt = 0;
                while (pagelinks == null & cnt < 10)
                {
                    pagelinks = driver.FindElements(By.CssSelector(css));
                    Thread.Sleep(1000);
                    cnt++;
                }
            }

            return(pagelinks);
        }
Ejemplo n.º 21
0
        internal bool WaitUntilLoading()
        {
            By     byLoading = By.ClassName("busy");
            string message   = null;

            try
            {
                if (driver.FindElement(byLoading).Displayed)
                {
                    do
                    {
                        message = driver.FindElement(byLoading).Text.ToUpper();
                        var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                        wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                        if (message == "AN ERROR HAS OCCURRED")
                        {
                            MyLogger.Log("<<AN ERROR HAS OCCURRED>> message displayed.");
                            return(false);
                        }
                        Thread.Sleep(10);
                    }while (message == "LOADING...");
                }
                return(true);
            }
            catch
            {
                return(true);
            }
        }
Ejemplo n.º 22
0
        public Driver waitUntilPageLoaded()
        {
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

            return(this);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Waits for element.
        /// </summary>
        /// <param name="elemId">Element identifier.</param>
        public void WaitForElement(string elemId)
        {
            IWebDriver driver = Factory.Instance;

            Console.WriteLine("WaitForElement id '{0}'", elemId);
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(Browsers.DefaultTimeoutInSeconds));

            wait.Until(d => d.FindElement(By.Id(elemId)));
        }
Ejemplo n.º 24
0
 private bool NavigateToSearchUrl()
 {
     try
     {
         IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(submit_wait));
         Thread.Sleep(1000);
         wait.Until(ExpectedConditions.ElementExists(By.Id("portlet-29")));
         var    smartSearhDiv  = driver.FindElementById("portlet-29");
         var    smartSearchA   = smartSearhDiv.FindElement(By.CssSelector("a"));
         string smartSearchUrl = smartSearchA.GetAttribute("href");
         driver.Navigate().GoToUrl(smartSearchUrl);
         wait.Until(ExpectedConditions.ElementExists(By.CssSelector("#SSColumn")));
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 25
0
 public static void WaitForElementNotVisible(By locator)
 {
     try
     {
         var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(Browser.GetDriver(), TimeSpan.FromMilliseconds(Convert.ToDouble(Configuration.GetTimeout())));
         wait.Until(driver1 => !visibility(locator));
     }
     catch (WebDriverTimeoutException)
     {
     }
 }
Ejemplo n.º 26
0
 public bool IsAt(By by)
 {
     try
     {
         wait.Until(ExpectedConditions.ElementIsVisible(by));
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
        public static IWebElement WaitForElement(this IWebDriver driver, string css, int time = 120)
        {
            OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(time));

            var pagelinks = wait.Until((d) =>
            {
                return(d.FindElement(By.CssSelector(css)));
            });


            return(pagelinks);
        }
Ejemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="we"></param>
 public QA.IWebElement WaitForElement(QA.By locator, int seconds)
 {
     UI.WebDriverWait _wait = new UI.WebDriverWait(wd, TimeSpan.FromSeconds(seconds));
     _wait.Until((d) => { return(SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(locator)); });
     QA.IWebElement theElement = null;
     try
     {
         theElement = (QA.IWebElement)wd.FindElement(locator);
     }
     catch { }
     return(theElement);
 }
        public static void OpenCollapsePanel(IWebDriver driver, string collapse_id, string panel_name)
        {
            string base_path = String.Format("//div[@id='{0}']/div[@value='{1}']",
                                             collapse_id, panel_name);
            string link_path       = base_path + "/div[@class='panel-heading']/h4/a";
            string content_path    = base_path + "/div[2]";
            string class_attribute = driver.FindElement(By.XPath(content_path)).GetAttribute("class");

            if (!class_attribute.Split().Contains("in"))
            {
                if (!driver.FindElement(By.XPath(link_path)).Displayed)
                {
                    ScrollToElement(driver, driver.FindElement(By.XPath(link_path)));
                }
                driver.FindElement(By.XPath(link_path)).Click();
                WebDriverWait wait    = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(5.0));
                IWebElement   content = driver.FindElement(By.XPath(content_path));
                wait.Until(d => content.GetAttribute("class").Split().Contains("in"));
                wait.Until(d => content.GetAttribute("style") == "");
            }
        }
Ejemplo n.º 30
0
    public void WaitOnWebPageLoad(double time)
    {
        try
        {
            IWait <IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(this, TimeSpan.FromSeconds(time));
            wait.Until(driver1 => ((IJavaScriptExecutor)this).ExecuteScript("return document.readyState").Equals("complete"));
        }

        catch (Exception ex)
        {
            tb.LogMe("GoToURL", ex);
        }
    }
Ejemplo n.º 31
0
 /// <summary>
 /// Retries the wait for document loaded.
 /// </summary>
 private void _RetryWaitForDocumentLoaded()
 {
     IWebDriver driver = Factory.Instance;
     IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(Browsers.DefaultTimeoutInSeconds));
     wait.Until(d => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
 }
Ejemplo n.º 32
0
		/// <summary>
		/// Waits for element.
		/// </summary>
		/// <param name="elemId">Element identifier.</param>
		public void WaitForElement(string elemId)
		{
			IWebDriver driver = Factory.Instance;
            Console.WriteLine("WaitForElement id '{0}'", elemId);
			IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(Browsers.DefaultTimeoutInSeconds));
			wait.Until(d => d.FindElement(By.Id(elemId)));
		}
Ejemplo n.º 33
0
        /// <summary>
        ///  Method to Method to verify page display by verifying page title.
        /// </summary>
        /// <param name="title">Title of web page</param>
        /// <returns>boolean value</returns>
        public bool VerifyPageDisplayed(Dictionary<int, string> keyWorddic)
        {
            try
            {
                bool isKeyVerified;
                string url = this.GetData(KryptonConstants.WHAT);
                if (!keyWorddic.Count.Equals(0))
                {
                    try
                    {
                        IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                        wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                        Browser.switchToMostRecentBrowser();
                    }
                    catch { }
                    isKeyVerified = Common.Utility.doKeywordMatch(url, driver.Url);
                }
                else
                {
                    //By Default regular expression match would be done for Url entry in OR.
                    try
                    {
                        IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                        wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                        Browser.switchToMostRecentBrowser();
                    }
                    catch { }
                    try
                    {
                        driver.SwitchTo().DefaultContent();
                    }
                    catch (Exception ed)
                    {
                        //do nothing
                    }
                    Regex regExp = new Regex(url.ToLower());
                    Match m = regExp.Match((driver.Url).ToLower());
                    isKeyVerified = m.Success;
                }

                if (!isKeyVerified)
                {
                    Common.Property.Remarks = "Page with URL: \"" + url + "\" is not displayed." +
                                              "Actual displayed page was: " + driver.Url;
                }

                return isKeyVerified;
            }
            catch (WebDriverException e)
            {
                if (e.Message.Contains(Common.exceptions.ERROR_NORESPONSEURL))
                {
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0054") + ":" + e.Message);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        ///  Method to Verify specified text is present in web page view source code .
        /// </summary>
        /// <param name="text">Text to verify</param>
        /// <returns>boolean value</returns>
        public bool VerifyTextInPageSource(string text, Dictionary<int, string> KeyWordDic)
        {
            try
            {
                try
                {
                    IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                    wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                    Browser.switchToMostRecentBrowser();
                }
                catch { }

                bool isKeyVerified;
                string s = driver.PageSource;
                s = s.Replace("<br />", "<br>");
                s = s.Replace("<BR/>", "<br>");
                if (!KeyWordDic.Count.Equals(0))
                {
                    isKeyVerified = Common.Utility.doKeywordMatch(text, s);
                }
                else
                {
                    isKeyVerified = s.Contains(text);
                }
                if (!isKeyVerified)
                {
                    Common.Property.Remarks = "Actual text : \"" + text + "\" is not found";
                }
                return isKeyVerified;
            }
            catch (WebDriverException e)
            {
                if (e.Message.Contains(Common.exceptions.ERROR_NORESPONSEURL))
                {
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0054") + ":" + e.Message);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 35
0
        /// <summary>
        ///  Method to verify specied text on web page.
        /// </summary>
        /// <param name="text">Text to verify on web page</param>
        /// <returns>boolean value</returns>
        ///
        public bool VerifyTextPresentOnPage(string text, Dictionary<int, string> KeywordDic)
        {
            try
            {

                bool isKeyVerified = true;
                text = text.Trim();
                // Replace special characters here
                text = Common.Utility.ReplaceSpecialCharactersInString(text);
                try
                {
                    IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                    wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                    Browser.switchToMostRecentBrowser();
                }
                catch { }
                IWebElement element = driver.FindElement(By.XPath("//html"));
                string pageText = element.Text.ToString().Trim();

                if (!KeywordDic.Count.Equals(0))
                {
                    isKeyVerified = Common.Utility.doKeywordMatch(text, pageText);
                }
                else
                {
                    isKeyVerified = pageText.Contains(text);
                }
                if (!isKeyVerified)
                {
                    Common.Property.Remarks = "Text : \"" + text + "\" is not found";
                }
                return isKeyVerified;
            }
            catch (WebDriverException e)
            {
                if (e.Message.Contains(Common.exceptions.ERROR_NORESPONSEURL))
                {
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0054") + ":" + e.Message);
            }
            catch (Exception e1)
            {
                throw;
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        ///  Method to return value of property if found other wise return null
        /// </summary>
        /// <param name="propertyType"> Type of property to get from test object.</param>
        /// <returns>Property value</returns>
        public string GetPageProperty(string propertyType)
        {
            try
            {
                try
                {
                    IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
                    wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
                    Browser.switchToMostRecentBrowser();
                }
                catch
                {
                // will not affect normal test case flow.
                }

                switch (propertyType.ToLower())
                {
                    case "title":
                        return driver.Title;
                    case "url":
                        return driver.Url;
                    default:
                        return null; ;
                }
            }
            catch (WebDriverException e)
            {
                if (e.Message.Contains(Common.exceptions.ERROR_NORESPONSEURL))
                {
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0054") + ":" + e.Message);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private static void Wait(ChromeDriver driver)
        {
            IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

            wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
        }
Ejemplo n.º 38
0
 //Wait till loading completed
 public void WaitforLoading(int timeout)
 {
     IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
     wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
 }
    protected void Button4_Click(object sender, EventArgs e)
    {
        // Response.Write(marker_place);
        List<string> lst_zipscodes = new List<string>();
        IGeocoder geocoder = new GoogleGeocoder() { };
        DataSet ds = new DataSet("Sites_Collection");
        string connection_string = ConfigurationManager.ConnectionStrings["UA_NAVConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connection_string);

        WeatherReference.WeatherSoapClient weather = new WeatherReference.WeatherSoapClient("WeatherSoap");

        // my source starting placeplace

        for (int i = 0; i < marker_place.Count; i++)
        {
            string source = marker_place[i];
            string[] addr_string = source.Split(',');
            string[] zipcode = null;
            if (addr_string.Count() == 4)
            {
                zipcode = addr_string[2].Trim().Split(' ');
                source = addr_string[1] + "," + zipcode[0];
                lst_zipscodes.Add(zipcode[1]);
            }
            else
            {
                continue;
            }
            IWebDriver driver = null;
            try
            {
                driver = new FirefoxDriver();

                driver.Navigate().GoToUrl("http://www.nwf.org/naturefind.aspx");
                driver.Manage().Window.Maximize();

                var place_name = driver.FindElement(By.Id("content_0_txtBasicSearch"));
                place_name.Clear();
                place_name.SendKeys(source);
                driver.FindElement(By.Id("content_0_btnSearchSites")).Click();
                //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

                IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(15.00));
                // IWait<IWebDriver> wait = null;
                wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

                DataTable dt = new DataTable("Places_" + i);

                DataColumn place_Coulumn = new DataColumn("Scenic_Place_Name", Type.GetType("System.String"));
                DataColumn lat_Coulumn = new DataColumn("Latitude", Type.GetType("System.String"));
                DataColumn lng_Coulumn = new DataColumn("Longitude", Type.GetType("System.String"));
                DataColumn address_of_place = new DataColumn("Address", Type.GetType("System.String"));
                DataColumn Zipscode = new DataColumn("Zipcode", Type.GetType("System.String"));
                DataColumn weather_desc = new DataColumn("Weather", Type.GetType("System.String"));
                DataColumn temperature = new DataColumn("Temperature", Type.GetType("System.String"));
                DataColumn traffic = new DataColumn("Traffic", Type.GetType("System.String"));
                DataColumn safety = new DataColumn("Safety", Type.GetType("System.String"));
                dt.Columns.Add(place_Coulumn);
                dt.Columns.Add(lat_Coulumn);
                dt.Columns.Add(lng_Coulumn);
                dt.Columns.Add(address_of_place);
                dt.Columns.Add(Zipscode);
                dt.Columns.Add(weather_desc);
                dt.Columns.Add(temperature);
                dt.Columns.Add(traffic);
                dt.Columns.Add(safety);

                DataRow dr;
                int count1 = 0;

                try
                {

                    wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u")));
                    wait.Until(ExpectedConditions.ElementExists(By.XPath("//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u")));
                    IList<IWebElement> lst_places = driver.FindElements(By.XPath(".//div[@id='content_0_grdSiteList']//tr[@class='rgRow']//u"));

                    if (lst_places == null)
                        continue;
                    int count = 0;
                    foreach (IWebElement place in lst_places)
                    {
                        //   if (count1!= -1)
                        //    {
                        try
                        {
                            dr = dt.NewRow();
                            Thread.Sleep(200);
                            dr["Scenic_Place_Name"] = place.Text;
                            IEnumerable<Address> addresses = geocoder.Geocode(place.Text + "," + zipcode[0]);
                            string place_addr = null;
                            Location ltng = null;

                            foreach (Address adr in addresses)
                            {
                                if (count == 0)
                                {
                                    place_addr = adr.FormattedAddress;
                                    ltng = adr.Coordinates;
                                    dr["Address"] = place_addr;
                                    break;
                                }
                            }

                            dr["Latitude"] = ltng.Latitude;
                            dr["Longitude"] = ltng.Longitude;

                            //tokenize place address

                            string[] array = place_addr.Split(',');
                            string[] waypoints = place_addr.Split(','); ///////*******************
                            string zip = array[array.Length - 2];
                            string[] arr = zip.Trim().Split(' ');
                            string webservicezip = null;
                            if (arr.Length == 1)
                            {
                                dr["Zipcode"] = zipcode[1];
                                webservicezip = zipcode[1];
                            }
                            else if (Regex.IsMatch(place_addr, @"\d"))
                            {
                                arr = zip.Trim().Split(' ');
                                dr["Zipcode"] = arr[1].Trim();
                                webservicezip = arr[1].Trim();
                            }

                            //weather update

                            WeatherReference.WeatherReturn weather_of_place = weather.GetCityWeatherByZIP(webservicezip);  //  arr[1].Trim()
                            dr["Weather"] = weather_of_place.Description;
                            dr["Temperature"] = weather_of_place.Temperature;

                            Random rnd = new Random();
                            dr["Traffic"] = rnd.Next(2, 5);
                            dr["Safety"] = rnd.Next(60, 100);
                            dt.Rows.Add(dr);
                            //break;
                        }

                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            continue;
                        }
                    }

                }
                finally
                {

                    ds.Tables.Add(dt);
                }

            }

            finally
            {
                driver.Close();
                driver.Dispose();
            }
        }

        WriteDataToDATABASE(ds);
        string[] scenic_places = CreateListScenicPlaces();
        //    DrawScenicDirection();
        foreach (string s in scenic_places)
        {
            ClientScript.RegisterArrayDeclaration("scenic_places", "\"" + s + "\"");
        }

        ClientScript.RegisterStartupScript(Page.GetType(), "Scenic", "scenic_route();", true);
    }