public TestSearchContext(TestSettings settings, By selfSelector, ISearchContext context,Func<IWebElement> selfLookup) { _settings = settings; _selfSelector = selfSelector; _context = context; _selfLookup = selfLookup; }
public ReadOnlyCollection<IWebElement> FindElements(By @by) { var element = _context as IWebElement; return new EagerReadOnlyCollection<IWebElement>(() => (element != null ? TestInteractionWrapper.Interact(ref element, _selfSelector, () => _selfLookup(), lmnt => _selfLookup().FindElements(@by)) : _context.FindElements(@by)) .Select((lmnt, index) => { //each element must be able to re-resolve it self //in this case, re-resolve all elements again and just pick the //element that has the same index as before return new TestWebElement(_settings, lmnt, @by, this, ctx => { var children = _selfLookup == null ? _context.FindElements(@by) : _selfLookup().FindElements(@by); return children.ElementAt(index); }); }) ); }
/// <summary> /// Lookup a reference field value. /// </summary> /// <param name="driver"></param> /// <param name="by">A mechanism by which to find the desired reference field within the current document.</param> /// <param name="sendKeys">A property value of the current reference field.</param> public static void Lookup(this IWebDriver driver, By by, string sendKeys) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); IWebElement lookup = wait.Until(ExpectedConditions.ElementIsVisible(by)); lookup.Click(); string currentWindowHandle = driver.CurrentWindowHandle; string searchWindow = driver.WindowHandles.First(o => o != currentWindowHandle); driver.SwitchTo().Window(searchWindow); IWebElement searchFor = wait.Until(ExpectedConditions.ElementExists(By.ClassName("list_search_text"))); searchFor.Click(); searchFor.Clear(); searchFor.SendKeys(sendKeys); var selects = driver.FindElements(By.ClassName("list_search_select")); IWebElement search = selects.First(o => o.GetAttribute("id").Contains("_select")); driver.SelectOption(search, "Name"); //"for text"); wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("img[title='Go']"))).Click(); IWebElement item = wait.Until(ExpectedConditions.ElementExists(By.LinkText(sendKeys))); item.Click(); driver.SwitchTo().Window(currentWindowHandle); driver.SwitchTo().Frame("gsft_main"); }
public PolicyResultCacheStrategy(string controllerName, string actionName, Type policyType, Cache cacheLifecycle, By cacheLevel = By.ControllerAction) { ControllerName = controllerName; ActionName = actionName; PolicyType = policyType; CacheLifecycle = cacheLifecycle; CacheLevel = cacheLevel; }
/// <summary> /// Waits for the element to be present present with a optional time. /// </summary> /// <param name="browser">The browser.</param> /// <param name="locator">The locator.</param> /// <param name="timeSpan">The time span.</param> public static void ElementPresent(IWebDriver browser, By locator, TimeSpan? timeSpan = null) { if (timeSpan == null) { timeSpan = TimeSpan.FromSeconds(10); } WaitForElement(browser, locator, (TimeSpan) timeSpan); }
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv.FindElement(by)); } return driver.FindElement(by); }
public static ReadOnlyCollection<IWebElement> FindElements(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => (drv.FindElements(by).Count > 0) ? drv.FindElements(by) : null); } return driver.FindElements(by); }
public RankedPair Find(By findBy) { if (persons.Count < 2) return new RankedPair(); var pairListing = (from person in persons from person1 in persons.Skip(persons.IndexOf(person) + 1) select person.BirthDate < person1.BirthDate ? new RankedPair(person, person1) : new RankedPair(person1, person)).OrderBy(x => x.AgeGap); return findBy == By.Closest ? pairListing.First() : pairListing.Last(); }
/// <summary> /// Initializes a new instance of the <see cref="ByIdOrName"/> class. /// </summary> /// <param name="elementIdentifier">The ID or Name to use in finding the element.</param> public ByIdOrName(string elementIdentifier) { if (string.IsNullOrEmpty(elementIdentifier)) { throw new ArgumentException("element identifier cannot be null or the empty string", "elementIdentifier"); } this.elementIdentifier = elementIdentifier; this.idFinder = By.Id(this.elementIdentifier); this.nameFinder = By.Name(this.elementIdentifier); }
private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } }
public static bool HasElement(this IWebDriver driver, By by) { try { driver.FindElement(by); } catch (NoSuchElementException) { return false; } return true; }
public static bool isPresent(this IWebDriver driver, By bylocator) { bool variable = false; try { IWebElement element = driver.FindElement(bylocator); variable = element != null; } catch (NoSuchElementException) { } return variable; }
public void Highlight(By locator, bool reset) { IWebElement element; try { element = _driver.FindElement(locator); } catch (Exception) { return; } HighlightElement(element, reset); }
/// <summary> /// Find an element, waiting until a timeout is reached if necessary. /// </summary> /// <param name="context">The search context.</param> /// <param name="by">Method to find elements.</param> /// <param name="timeout">How many seconds to wait.</param> /// <param name="displayed">Require the element to be displayed?</param> /// <returns>The found element.</returns> public static IWebElement FindElement(this ISearchContext context, By by, uint timeout, bool displayed = false) { var wait = new DefaultWait<ISearchContext>(context); wait.Timeout = TimeSpan.FromSeconds(timeout); wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); return wait.Until(ctx => { var elem = ctx.FindElement(by); if (displayed && !elem.Displayed) return null; return 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. /// </summary> /// <param name="locator">The locator used to find the element.</param> /// <returns>The <see cref="IWebElement"/> once it is located and visible.</returns> public static Func<IWebDriver, IWebElement> ElementIsVisible(By locator) { return (driver) => { try { return ElementIfVisible(driver.FindElement(locator)); } catch (StaleElementReferenceException) { return null; } }; }
/// <summary> /// Lookup a reference field value. /// </summary> /// <param name="driver"></param> /// <param name="by">A mechanism by which to find the desired reference field within the current document.</param> /// <param name="what">A property of the current reference field.</param> /// <param name="sendKeys">A property value of the current reference field.</param> public static void Lookup(this IWebDriver driver, By by, string what, string sendKeys) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.ElementIsVisible(by)).Click(); string currentWindowHandle = driver.CurrentWindowHandle; string searchWindow = driver.WindowHandles.First(o => o != currentWindowHandle); driver.SwitchTo().Window(searchWindow); Search(driver, what, sendKeys); System.Threading.Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementIsVisible(By.LinkText(sendKeys))).Click(); driver.SwitchTo().Window(currentWindowHandle); driver.SwitchTo().Frame("gsft_main"); }
public IWebElement FindElement(By @by) { var element = _context as IWebElement; if (element != null) { //Console.WriteLine("element->element: {0}", @by); return TestInteractionWrapper.Interact( ref element, _selfSelector, () => _selfLookup(), lmnt => new TestWebElement(_settings, lmnt, _selfSelector, this, ctx => ctx.FindElement(@by)) ); } //context is IWebDriver, no need to guard for stale element //Console.WriteLine("driver->element: {0}", @by); element = _context.FindElement(@by); return new TestWebElement(_settings, element, @by, _context, ctx => ctx.FindElement(@by)); }
public void FindMainWindow() { this.MainWindow = this.Driver.FindElement(By.XPath("/*[@AutomationId='WpfTestApplicationMainWindow']")); }
public IWebElement FindWebElementAndWait(By by) => DriverHelper.FindWebElementAndWait(Driver, by);
/// <summary> /// Finds all <see cref="IWebElement">IWebElements</see> within the current context /// using the given mechanism. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>A <see cref="ReadOnlyCollection{T}"/> of all <see cref="IWebElement">WebElements</see> /// matching the current criteria, or an empty list if nothing matches.</returns> public ReadOnlyCollection<IWebElement> FindElements(By by) { if (by == null) { throw new ArgumentNullException("by", "by cannot be null"); } return by.FindElements(this); }
internal ElementPresentError(By by) : base(77, "Element not expected for {0}", by.ToString()) { }
public IList <IWebElement> FindWebElements(By by) => DriverHelper.FindWebElementsWithoutWait(Driver, by);
public void OB() { // to get previous month for file dating and time reports date = date.AddMonths(-1); int m = date.Month; int y = date.Year; //Gets number of days in the month for use as the end date of the corresponding month, automatically string endDate = DateTime.DaysInMonth(y, m).ToString(); string month = date.ToString("MMM"); string year = date.ToString("yyyy"); //** //Begin test driver.Navigate().GoToUrl(baseURL); driver.Manage().Window.Maximize(); Actions action = new Actions(this.driver); //This is where actions start.. Page has opened and maximized.. Thread.Sleep(750); //Test Start //Login driver.FindElement(By.Id("username")).SendKeys("*****@*****.**"); driver.FindElement(By.Id("password")).SendKeys("Sapp8447" + Keys.Enter); Thread.Sleep(4000); //Orchard Brands driver.FindElement(By.LinkText("Orchard Brands QA Extension")).Click(); Thread.Sleep(3000); driver.FindElement(By.LinkText("Time")).Click(); Thread.Sleep(1000); //Create 1st Report driver.FindElement(By.Id("report_link")).Click(); Thread.Sleep(750); //Selecting user from dropdown 1 driver.FindElement(By.Id("subject_id")).Click(); driver.FindElement(By.Id("subject_id")).SendKeys("Heather Hughes" + Keys.Enter); Thread.Sleep(750); //starting date select 2 driver.FindElement(By.Id("from_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).SendKeys(month + " " + year + Keys.Enter); Thread.Sleep(750); driver.FindElement(By.LinkText("1")).Click(); Thread.Sleep(750); //ending date select 3 driver.FindElement(By.Id("to_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.LinkText(endDate)).Click(); Thread.Sleep(750); driver.FindElement(By.Id("to_date_display")).SendKeys(Keys.Enter); Thread.Sleep(750); //saving time slot to variable 4 string heather = "Heather Hughes = " + driver.FindElement(By.Id("hours_subtotal")).Text + " \r\n"; Thread.Sleep(3000); //Create 2nd Report driver.FindElement(By.Id("report_link")).Click(); Thread.Sleep(750); //1 driver.FindElement(By.Id("subject_id")).Click(); driver.FindElement(By.Id("subject_id")).SendKeys("Ethan Dutton" + Keys.Enter); Thread.Sleep(750); //2 driver.FindElement(By.Id("from_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).SendKeys(month + " " + year + Keys.Enter); Thread.Sleep(750); driver.FindElement(By.LinkText("1")).Click(); Thread.Sleep(750); //3 driver.FindElement(By.Id("to_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.LinkText(endDate)).Click(); Thread.Sleep(750); driver.FindElement(By.Id("to_date_display")).SendKeys(Keys.Enter); Thread.Sleep(750); //4 string ethan = "Ethan Dutton = " + driver.FindElement(By.Id("hours_subtotal")).Text + " \r\n"; Thread.Sleep(3000); //Create 3rd Report driver.FindElement(By.Id("report_link")).Click(); Thread.Sleep(750); //1 driver.FindElement(By.Id("subject_id")).Click(); driver.FindElement(By.Id("subject_id")).SendKeys("Tracy Smith" + Keys.Enter); Thread.Sleep(750); //2 driver.FindElement(By.Id("from_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).SendKeys(month + " " + year + Keys.Enter); Thread.Sleep(750); driver.FindElement(By.LinkText("1")).Click(); Thread.Sleep(750); //3 driver.FindElement(By.Id("to_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.LinkText(endDate)).Click(); Thread.Sleep(750); driver.FindElement(By.Id("to_date_display")).SendKeys(Keys.Enter); Thread.Sleep(750); //4 string tracy = "Tracy Smith = " + driver.FindElement(By.Id("hours_subtotal")).Text + " \r\n"; Thread.Sleep(3000); //Create 4th Report driver.FindElement(By.Id("report_link")).Click(); Thread.Sleep(750); //1 driver.FindElement(By.Id("subject_id")).Click(); driver.FindElement(By.Id("subject_id")).SendKeys("Anita Acharya" + Keys.Enter); Thread.Sleep(750); //2 driver.FindElement(By.Id("from_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).Click(); Thread.Sleep(750); driver.FindElement(By.ClassName("months")).SendKeys(month + " " + year + Keys.Enter); Thread.Sleep(750); driver.FindElement(By.LinkText("1")).Click(); Thread.Sleep(750); //3 driver.FindElement(By.Id("to_date_display")).Click(); Thread.Sleep(750); driver.FindElement(By.LinkText(endDate)).Click(); Thread.Sleep(750); driver.FindElement(By.Id("to_date_display")).SendKeys(Keys.Enter); Thread.Sleep(750); //4 string anita = "Anita Acharya = " + driver.FindElement(By.Id("hours_subtotal")).Text + " \r\n"; Thread.Sleep(3000); //Combining Time Slots contents = heather + ethan + tracy + anita; //Creating client folder in current user's documents folder if it does not exist if (!Directory.Exists(docs + "\\OB")) { Directory.CreateDirectory(docs + "\\OB"); } //Creating and writing slots to text file in client folder title with the appropriate numerical month and year date System.IO.File.WriteAllText(docs + "\\OB\\" + date.ToString("MMyyyy") + ".txt", contents); //End of Test //** //IList<IWebElement> check = driver.FindElements(By.ClassName("check")); //check.ElementAt(1).Click(); //used to pull numbers from a text document to use as variables //var dic = File.ReadAllLines("C:\\Users\\Admin\\Desktop\\variables.txt") // .Select(l => l.Split(new[] { '=' })) // .ToDictionary(s => s[0].Trim(), s => s[1].Trim()); }
public void IsCountryDisplayed(string expectedText) { IWebElement countryDisplay = driver.FindElement(By.Id("select2-country-container")); Assert.AreEqual(expectedText, countryDisplay.Text); }
public int CountrySearchResults(string searchText, out List <string> searchResultList) { List <string> actualSearchList = new List <string>(); foreach (var item in originalCountryList) { if (item.Contains(searchText)) { actualSearchList.Add(item); } else if (searchText.Length == 1) { if (item.Contains(searchText.ToUpper())) { actualSearchList.Add(item); } else if (item.Contains(searchText.ToLower())) { actualSearchList.Add(item); } } } IReadOnlyCollection <IWebElement> actualElementsList = countryList.FindElements(By.CssSelector("li")); Assert.AreEqual(actualSearchList.Count, actualElementsList.Count); foreach (var item in actualSearchList) { foreach (var element in actualElementsList) { if (item == element.Text) { Assert.AreEqual(item, element.Text); break; } } } searchResultList = actualSearchList; return(actualElementsList.Count); }
public static void ResetZoom(this IWebDriver driver) { IWebElement element = driver.FindElement(By.TagName("body")); element.SendKeys(Keys.Control + "0"); }
public void RemoveGroup() { driver.FindElement(By.Name("delete")).Click(); }
public static void NavigateToMailContact(TestContext testContext) { string organizationName = Convert.ToString(testContext.DataRow["OrganizationName"]); try { SetDriverTime(2); if (DriverContext.Driver.FindElements(By.XPath("//h2")).Count == 0) { SetDriverTime(30); HomePage home = new HomePage(); home.ClickProvisioning(); ExchangeHome exgHome = home.ClickExchangeHome(); exgHome.SearchOrganizationName(organizationName); exgHome.MailContactHome(); } else if (DriverContext.Driver.FindElement(By.XPath("//h2")).Text != "Manage Mail Contacts" && !DriverContext.Driver.FindElement(By.XPath("//p")).Text.Contains(organizationName)) { SetDriverTime(30); PageRefresh(DriverContext.Driver); //Act HomePage home = new HomePage(); home.ClickProvisioning(); ExchangeHome exgHome = home.ClickExchangeHome(); exgHome.SearchOrganizationName(organizationName); exgHome.MailContactHome(); } } catch (Exception) { } }
public void ThenTheShouldBePresent(string storyXpath) { var xPath = WebDriver.Driver.FindElement(By.XPath(storyXpath)); Assert.IsTrue(xPath.Displayed); }
public void WhenNewsPageIsOpened() { OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(WebDriver.Driver, TimeSpan.FromSeconds(3)); wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id=\"responsive-news\"]/body"))); }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); if (data.Driver == null && action != BrowserAction.Open) { data.Log(new LogEntry("Open a browser first!", Colors.White)); throw new Exception("Browser not open"); } var replacedInput = ReplaceValues(input, data); switch (action) { case BrowserAction.Open: OpenBrowser(data); try { UpdateSeleniumData(data); } catch { } break; case BrowserAction.Close: data.Driver.Close(); data.BrowserOpen = false; break; case BrowserAction.Quit: data.Driver.Quit(); data.BrowserOpen = false; break; case BrowserAction.ClearCookies: data.Driver.Manage().Cookies.DeleteAllCookies(); break; case BrowserAction.SendKeys: var action = new Actions(data.Driver); foreach(var s in replacedInput.Split(new string[] { "||" }, StringSplitOptions.None)) { switch (s) { case "<TAB>": action.SendKeys(OpenQA.Selenium.Keys.Tab); break; case "<ENTER>": action.SendKeys(OpenQA.Selenium.Keys.Enter); break; case "<BACKSPACE>": action.SendKeys(OpenQA.Selenium.Keys.Backspace); break; case "<ESC>": action.SendKeys(OpenQA.Selenium.Keys.Escape); break; default: action.SendKeys(s); break; } } action.Perform(); Thread.Sleep(1000); if(replacedInput.Contains("<ENTER>") || replacedInput.Contains("<BACKSPACE>")) // These might lead to a page change UpdateSeleniumData(data); break; case BrowserAction.Screenshot: var image = data.Driver.GetScreenshot(); SaveScreenshot(image, data); break; case BrowserAction.SwitchToTab: data.Driver.SwitchTo().Window(data.Driver.WindowHandles[int.Parse(replacedInput)]); UpdateSeleniumData(data); break; case BrowserAction.Refresh: data.Driver.Navigate().Refresh(); break; case BrowserAction.Back: data.Driver.Navigate().Back(); break; case BrowserAction.Forward: data.Driver.Navigate().Forward(); break; case BrowserAction.Maximize: data.Driver.Manage().Window.Maximize(); break; case BrowserAction.Minimize: data.Driver.Manage().Window.Minimize(); break; case BrowserAction.FullScreen: data.Driver.Manage().Window.FullScreen(); break; case BrowserAction.SetWidth: data.Driver.Manage().Window.Size = new Size(int.Parse(replacedInput), data.Driver.Manage().Window.Size.Height); break; case BrowserAction.SetHeight: data.Driver.Manage().Window.Size = new Size(data.Driver.Manage().Window.Size.Width, int.Parse(replacedInput)); break; case BrowserAction.DOMtoSOURCE: data.ResponseSource = data.Driver.FindElement(By.TagName("body")).GetAttribute("innerHTML"); break; case BrowserAction.GetCookies: foreach(var cookie in data.Driver.Manage().Cookies.AllCookies) { try { data.Cookies.Add(cookie.Name, cookie.Value); } catch { } } break; case BrowserAction.SetCookies: var baseURL = Regex.Match(ReplaceValues(input, data), "^(?:https?:\\/\\/)?(?:[^@\\/\n]+@)?(?:www\\.)?([^:\\/?\n]+)").Groups[1].Value; foreach (var cookie in data.Cookies) { try { data.Driver.Manage().Cookies.AddCookie(new Cookie(cookie.Key, cookie.Value, baseURL, "/", DateTime.MaxValue)); } catch { } } break; case BrowserAction.SwitchToDefault: data.Driver.SwitchTo().DefaultContent(); break; case BrowserAction.SwitchToAlert: data.Driver.SwitchTo().Alert(); break; case BrowserAction.SwitchToParentFrame: data.Driver.SwitchTo().ParentFrame(); break; } data.Log(new LogEntry(string.Format("Executed browser action {0} on input {1}", action, ReplaceValues(input, data)), Colors.White)); }
public IList <IWebElement> FindWebElementsAndWait(By by) => DriverHelper.FindWebElementsAndWait(Driver, by);
public void InitGroupCreation() { driver.FindElement(By.Name("new")).Click(); }
public IPolicyContainerConfiguration DoNotCache(By level) { return(_inner.Cache <TCurrentSecurityPolicy>(Caching.Cache.DoNotCache, level)); }
public void SubmitGroupCreation() { driver.FindElement(By.Name("submit")).Click(); }
public IWebElement FindWebElement(By by) => DriverHelper.FindWebElementWithoutWait(Driver, by);
public void ReturnToGroupPage() { driver.FindElement(By.LinkText("group page")).Click(); }
public IPolicyContainerConfiguration Cache <TSecurityPolicy>(Cache lifecycle, By level) where TSecurityPolicy : ISecurityPolicy { return(_inner.Cache <TSecurityPolicy>(lifecycle, level)); }
public IPolicyContainerConfiguration CachePerHttpSession(By level) { return(_inner.Cache <TCurrentSecurityPolicy>(Caching.Cache.PerHttpSession, level)); }
internal AutoWatElement(By finder) : base(By.Body, null, false) { Finder = finder; }
/// <summary> /// Initializes a new instance of the <see cref="FindElementEventArgs"/> class. /// </summary> /// <param name="driver">The WebDriver instance used in finding elements.</param> /// <param name="element">The parent element used as the context for the search.</param> /// <param name="method">The <see cref="By"/> object containing the method used to find elements.</param> public FindElementEventArgs(IWebDriver driver, IWebElement element, By method) { this.driver = driver; this.element = element; this.method = method; }
public void SelectGroup(int index) { driver.FindElement(By.XPath("(//input[@name='selected[]'])[" + index + "]")).Click(); }
/// <summary> /// Finds the first element in the page that matches the <see cref="By"/> object /// </summary> /// <param name="by">By mechanism to find the element</param> /// <returns>IWebElement object so that you can interction that object</returns> public IWebElement FindElement(By by) { FindElementEventArgs e = new FindElementEventArgs(this.parentDriver.WrappedDriver, this.underlyingElement, by); this.parentDriver.OnFindingElement(e); IWebElement element = this.underlyingElement.FindElement(by); this.parentDriver.OnFindElementCompleted(e); IWebElement wrappedElement = this.parentDriver.WrapElement(element); return wrappedElement; }
/// <summary> /// Find all <see cref="IWebElement">IWebElements</see> within the current context /// using the given mechanism. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>A <see cref="ReadOnlyCollection{T}"/> of all <see cref="IWebElement">WebElements</see> /// matching the current criteria, or an empty list if nothing matches.</returns> public ReadOnlyCollection<IWebElement> FindElements(By by) { List<IWebElement> wrappedElementList = new List<IWebElement>(); FindElementEventArgs e = new FindElementEventArgs(this.driver, by); this.OnFindingElement(e); ReadOnlyCollection<IWebElement> elements = this.driver.FindElements(by); this.OnFindElementCompleted(e); foreach (IWebElement element in elements) { IWebElement wrappedElement = this.WrapElement(element); wrappedElementList.Add(wrappedElement); } return wrappedElementList.AsReadOnly(); }
public static string GetBodyText(this IWebDriver driver) { return(driver.FindElement(By.TagName("body")).Text); }
public StatusCodesForm() : base(By.Id("content"), "Status Codes") { }
/// <summary> /// Find the first <see cref="IWebElement"/> using the given method. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns> /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception> public IWebElement FindElement(By by) { IWebElement wrappedElement = null; try { FindElementEventArgs e = new FindElementEventArgs(this.driver, by); this.OnFindingElement(e); IWebElement element = this.driver.FindElement(by); this.OnFindElementCompleted(e); wrappedElement = this.WrapElement(element); } catch (Exception ex) { this.OnException(new WebDriverExceptionEventArgs(this.driver, ex)); throw; } return wrappedElement; }
/// <summary> /// Clears the focus from all elements. /// TODO: this implementation of the ClearFocus is clicking somewhere on the body, that may happen in some unwanted point, changing the results of the test. /// Clicking on the label of the current control may have a better result. /// </summary> /// <param name="driver">The driver.</param> public static void ClearFocus(this IWebDriver driver) { driver.FindElement(By.TagName("body")).Click(); }
/// <summary> /// Find the first <see cref="IWebElement"/> using the given method. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns> /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception> public IWebElement FindElement(By by) { FindElementEventArgs e = new FindElementEventArgs(this.driver, by); this.OnFindingElement(e); IWebElement element = this.driver.FindElement(by); this.OnFindElementCompleted(e); IWebElement wrappedElement = this.WrapElement(element); return wrappedElement; }
public static IWebElement ClickIfVisible(this ISearchContext driver, By by, TimeSpan?timeout = null) => WaitUntilClickable(driver, by, timeout ?? TimeSpan.FromSeconds(1), e => e.Click());
private bool IsElementAvailable(IWebDriver driver, By locator) { try { driver.FindElement(locator); return true; } catch (NoSuchElementException) { return false; } }
public static bool HasElement(this ISearchContext driver, By by) => driver.FindElements(by).Count > 0;
/// <summary> /// Initializes a new instance of the <see cref="FindElementEventArgs"/> class. /// </summary> /// <param name="driver">The WebDriver instance used in finding elements.</param> /// <param name="method">The <see cref="By"/> object containing the method used to find elements</param> public FindElementEventArgs(IWebDriver driver, By method) : this(driver, null, method) { }
public static IWebElement ClickWhenAvailable(this ISearchContext driver, By by, string errorMessage) => WaitUntilClickable(driver, by, null, e => e.Click(), errorMessage ?? "Unable to click element.");
/// <summary> /// Finds the first <see cref="IWebElement"/> using the given method. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns> /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception> public IWebElement FindElement(By by) { if (by == null) { throw new ArgumentNullException("by", "by cannot be null"); } return by.FindElement(this); }
public static IWebElement WaitUntilVisible(this ISearchContext driver, By by, TimeSpan timeout, string exceptionMessage) => WaitUntilVisible(driver, by, timeout, null, exceptionMessage);
internal ElementNotVisibleError(By by) : base(7, "Element not visible for {0}", by.ToString()) { }
public static IWebElement WaitUntilClickable(this ISearchContext driver, By by, string exceptionMessage) => WaitUntilClickable(driver, by, null, null, exceptionMessage);
internal NoSuchElementError(By by) : base(7, "Element not found for {0}", by.ToString()) { }
public static IWebElement WaitUntilClickable(this ISearchContext driver, By by, Action <IWebElement> successCallback, string exceptionMessage) => WaitUntilClickable(driver, by, null, successCallback, exceptionMessage);