/// <summary> /// Click and hold an element /// </summary> /// <param name="element">Page element</param> /// <param name="ms">Number of milliseconds to hold down the click</param> public static void ClickLong(this IBrowser browser, PageElement element, int ms) { var action = new Actions(browser.IWebDriver); action.ClickAndHold(browser.Find(element)).Build().Perform(); Thread.Sleep(ms); action.Release(browser.Find(element)).Build().Perform(); }
/// <summary> /// Select from a dropdown by text /// </summary> /// <param name="element">Select element</param> /// <param name="text">Option text</param> public static void SelectByText(this IBrowser browser, SelectElement element, string text) { // Create selenium select element object var select = new OpenQA.Selenium.Support.UI.SelectElement(browser.Find(element)); // Select by value select.SelectByText(text); }
/// <summary> /// Select from a dropdown by index /// </summary> /// <param name="element">Select element</param> /// <param name="text">Option index</param> public static void SelectByIndex(this IBrowser browser, SelectElement element, int value) { // Create selenium select element object var select = new OpenQA.Selenium.Support.UI.SelectElement(browser.Find(element)); // Select by value select.SelectByIndex(value); }
/// <summary> /// Find a page element's IWebElement /// </summary> /// <param name="element">Page Element to search for</param> /// <returns>IWebElement of the page element</returns> public static IWebElement Find(this IBrowser browser, PageElement element) { try { switch (element.Type.ToLower()) { case "id": return(browser.IWebDriver.FindElement(By.Id(element.Locator))); case "class": return(browser.IWebDriver.FindElement(By.ClassName(element.Locator))); case "css": return(browser.IWebDriver.FindElement(By.CssSelector(element.Locator))); case "link": return(browser.IWebDriver.FindElement(By.LinkText(element.Locator))); case "name": return(browser.IWebDriver.FindElement(By.Name(element.Locator))); case "partial-link": return(browser.IWebDriver.FindElement(By.PartialLinkText(element.Locator))); case "tag": return(browser.IWebDriver.FindElement(By.TagName(element.Locator))); case "href": return(browser.IWebDriver.FindElement(By.CssSelector("[href='" + element.Locator + "']"))); case "xpath": return(browser.IWebDriver.FindElement(By.XPath(element.Locator))); default: if (element.Type.Contains("data-")) { return(browser.IWebDriver.FindElement(By.CssSelector("[" + element.Type + "='" + element.Locator + "']"))); } else { throw new PageElementTypeException("'" + element.Type + "' is not a valid type to find a page element by."); } } } catch (NoSuchElementException) { try { browser.WaitForElementPresent(element); return(browser.Find(element)); } catch (BrowserTimeoutException bte) { throw new PageElementNotFoundException("Browser timed out trying to find element.", bte); } } }
/// <summary> /// Wait for a page element to disappear /// </summary> /// <param name="element">Page element waiting on to disappear</param> public static void WaitForElementNotPresent(this IBrowser browser, PageElement element) { var start = DateTime.Now; while (DateTime.Now.Subtract(start).Seconds < Common.BrowserTimeout.Seconds) { try { IWebElement temp = browser.Find(element); Thread.Sleep(200); } catch (NoSuchElementException) { return; } } throw new BrowserTimeoutException("Timeout: Element continues to stay present."); }
private ISearchContext CreateSearchContext(IBrowser my) { ISearchContext ctx = new WebElement(my.Find("html", new object())); return ctx; }
/// <summary> /// Hover the pointer over an element /// </summary> /// <param name="element">Page element</param> public static void Hover(this IBrowser browser, PageElement element) { var action = new Actions(browser.IWebDriver); action.MoveToElement(browser.Find(element)).Build().Perform(); }
/// <summary> /// Double click an element /// </summary> /// <param name="element">Page element</param> public static void ClickDouble(this IBrowser browser, PageElement element) { var action = new Actions(browser.IWebDriver); action.DoubleClick(browser.Find(element)).Build().Perform(); }
/// <summary> /// Click an element /// </summary> /// <param name="element">Page element</param> public static void Click(this IBrowser browser, PageElement element) { browser.Find(element).Click(); }
/// <summary> /// Read the text inside the field /// </summary> /// <param name="element">Text element</param> /// <returns>Inner text</returns> public static string ReadText(this IBrowser browser, TextElement element) { return(browser.Find(element).Text); }
/// <summary> /// Insert text into field /// </summary> /// <param name="element">Text element</param> /// <param name="text">Input text</param> public static void InsertText(this IBrowser browser, TextElement element, string text) { browser.Find(element).SendKeys(text); }
public PageRoot(IBrowser browser) : base(browser.Find("html", new object ())) { _my = browser; }
private ISearchContext CreateSearchContext(IBrowser my) { ISearchContext ctx = new WebElement(my.Find("html", new object())); return(ctx); }
public PageRoot(IBrowser browser) : base(browser.Find("html", new object())) { _my = browser; }
protected override System.Xml.Linq.XNode GetXmlRootNode() { var re = _my.Find("html", new object()); return(re.XElement.Parent); }