public void GoogleTest() { BaseDriver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = BaseDriver.FindElement(By.Name("q")); query.SendKeys("Bread" + Keys.Enter); Thread.Sleep(2000); Assert.AreEqual("Bread - Google Search", BaseDriver.Title); BaseDriver.Quit(); }
private TElement ElementBy <TElement>(By by) where TElement : IElement { var WebElement = BaseDriver.FindElement(by); if (WebElement == null) { Logger.Info("Unable to locate : " + typeof(IElement).ToString() + " element using: " + by.ToString()); return(default(TElement)); } else { return((TElement)typeof(TElement) .GetConstructor(new[] { typeof(IWebElement), typeof(BaseDriver), typeof(string) }) .Invoke(new object[] { WebElement, BaseDriver, by.ToString() })); } }
/// <summary> /// Helper method to determine whether an element is displayed within the given timeout. /// </summary> /// <param name="driver">The current driver in use.</param> /// <param name="element">The element to check.</param> /// <returns>True if element is displayed within the default timeout, false otherwise.</returns> public static bool IsDisplayed(BaseDriver driver, By element) { WebDriverWait wait = new WebDriverWait(driver, TIMEOUT); return(wait.Until(d => { try { IWebElement tempElement = driver.FindElement(element); return tempElement.Displayed; } catch { return false; } })); }
/// <summary> /// Finds a web element ny By. /// </summary> /// <param name="by">the strategy for finding the element</param> /// <returns>the <see cref="IWebElement"/></returns> public IWebElement FindElement(By by) { WaitsHandler.WaitForElementToBeVisible(BaseDriver, by, "element", "page"); return(BaseDriver.FindElement(by)); }