/// <summary> /// Finds the elements with timeout wait. /// </summary> /// <param name="driver">The driver.</param> /// <param name="by">The by.</param> /// <returns></returns> public static ReadOnlyCollection<IWebElement> FindElementsWithTimeoutWait(IWebDriver driver, By by) { Exception ex = null; ReadOnlyCollection<IWebElement> e = null; long elapsedTime = 0; while (elapsedTime < TimeOut) { try { elapsedTime++; StandardSleep(1); e = driver.FindElements(by); break; } catch (NoSuchElementException nse) { if (e == null) throw ex; } } if (e == null) throw ex; return e; }
public static void AssertElementPresent(ISearchContext context, By searchBy, string elementDescription) { if (!IsElementPresent(context, searchBy)) { throw new AssertionException(String.Format("AssertElementPresent Failed: Could not find '{0}'", elementDescription)); } }
public static IEnumerable<IWebElement> WaitUntilElementsInvisible(this IWebDriver driver, By selector) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(ExpectedConditions.InvisibilityOfElementLocated(selector)); return driver.FindElements(selector); }
public static IWebElement GetElement(By locator) { if (IsElemetPresent(locator)) return ObjectRepository.Driver.FindElement(locator); else throw new NoSuchElementException("Element Not Found : " + locator.ToString()); }
/// <summary> /// Construct an element /// </summary> /// <param name="locator">By locator</param> public Element(By locator): base() { this.name = "Element"; this.by = locator; this.pageObjectName = TestBase.GetCurrentClassName(); this.timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec; }
/// <summary> /// Construct an element /// </summary> /// <param name="locator">By locator</param> public Element(By locator) { name = "Element"; by = locator; pageObjectName = TestBase.GetCurrentClassName(); timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec; }
/// <summary> /// Construct an element /// </summary> /// <param name="name">Human readable name of the element</param> /// <param name="locator">By locator</param> public Element(string name, By locator) { this.name = name; by = locator; pageObjectName = TestBase.GetCurrentClassName(); timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec; }
/// <summary> /// Construct an element using an existing element /// </summary> /// <param name="element"></param> public Element(IWebElement element, By by) { this.element = element; this.by = by; pageObjectName = TestBase.GetCurrentClassName(); timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec; }
public SlidingSelect(IWebDriver driver, By arrowId, By listDropDownId) { _driver = driver; _arrowId = arrowId; _listDropDownId = listDropDownId; }
public static void CreateNewPortal(IWebDriver driver, string portalName, By template) { Login.AsHost(driver); driver.Navigate().GoToUrl(SiteManagementPage); driver.WaitClick(CreatePortalButton); driver.WaitClick(AddSiteSiteTypeChildRadio); driver.FindDnnElement(AddSitePortalAliasTextbox).Clear(); driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/"); driver.FindDnnElement(AddSitePortalAliasTextbox).Clear(); driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/"); driver.WaitSendKeys(AddSitePortalNameTextbox, portalName); driver.WaitClick(AddSiteTemplateInput); driver.WaitClick(template); driver.WaitClick(AddSiteCreateSiteButton); int origTimeout = Common.DriverTimeout; Common.DriverTimeout = 30000; driver.WaitClick(AddSiteVisitNewPortalLink); Common.DriverTimeout = origTimeout; }
public static string GetButtonText(By locator) { element = GenericHelper.GetElement(locator); if (element.GetAttribute("value") == null) return String.Empty; return element.GetAttribute("value"); }
public static void ScrollElementAndClick(By locator) { IWebElement element = ObjectRepository.Driver.FindElement(locator); GenericHelper.WaitForElement(element); ExecuteScript("window.scrollTo(0," + element.Location.Y + ");"); element.Click(); }
protected IWebElement waitForElementAndReturn(By selector) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(drv => driver.FindElement(selector) != null); return driver.FindElement(selector); }
public static IWebElement WaitElementIsRendered(this IWebDriver driver, By selector) { return Wait.Until(Timeouts.Default, () => FindElement(driver, selector), element => element != null && element.Displayed, $"Element with selector:{selector} could not be rendered"); }
public static string WaitTextIsRendered(this IWebDriver driver, By elementSelector) { return Wait.Until(Timeouts.Default, () => FindElement(driver, elementSelector)?.Text, text => !string.IsNullOrEmpty(text), $"Element with selector:{elementSelector} could not be rendered"); }
public static void ScrollToAndClick(By locator) { IWebElement element = GenericHelper.GetElement(locator); ExecuteScript("window.scrollTo(0," + element.Location.Y + ")"); Thread.Sleep(300); element.Click(); }
public void Selectanoption(IWebDriver driver, By by, string optiontoselect) { var data = driver.FindElement(@by); //IList<IWebElement> dataoptions = data.FindElements(By.TagName("option")); var select = new SelectElement(data); @select.SelectByText(optiontoselect); }
public static bool ElementIsDisplayed(this IWebDriver driver, By by) { System.Threading.Thread.Sleep(5); IWebElement el; bool isDisplayed = false; bool gotBoolean; if (driver.ElementExists(by)) { el = driver.FindElement(by); do { // For whatever reason, on Android this often throws an InvalidCastException try { isDisplayed = el.Displayed; gotBoolean = true; } catch (InvalidCastException) { // Loop until we get either a true or false gotBoolean = false; } } while (gotBoolean == false); return isDisplayed; } else { return false; } }
public static IEnumerable<IWebElement> WaitUntilElementsPresent(this IWebDriver driver, By selector) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(ExpectedConditions.ElementExists(selector)); return driver.FindElements(selector); }
public ByAttribute(By by, string attributeName, string attributeValue, Func<string, string, bool> attrComparisonMethod, Input input = Input.Type, bool visibleOnly = true) : base(by, input, visibleOnly) { Attributes = new Dictionary<string, string>(); Attributes.Add(attributeName, attributeValue); ComparisonMethod = attrComparisonMethod; }
public Element(string element) { if (string.IsNullOrEmpty(element)) return; // assume XPath expression if (element.Contains("/")) { this.element = By.XPath(element); return; } var token = element.Split('='); if (token.Length != 2) return; var key = token[0].Trim().ToLower(); var value = token[1].Trim(); if ("id".Equals(key)) { this.element = By.Id(value); } else if ("name".Equals(key)) { this.element = By.Name(value); } else if ("link".Equals(key)) { this.element = By.LinkText(value); } }
public void WaitForElementPresentAndEnabled(By locator, int secondsToWait = 30) { new WebDriverWait(this.driver, new TimeSpan(0, 0, secondsToWait)) .Until(d => d.FindElement(locator).Enabled && d.FindElement(locator).Displayed ); }
protected PageElement(By byLocator) { BaseElement = new CCElement(byLocator); if (ValidTags != null && !ValidTags.Contains(BaseElement.TagName.ToLower())) { throw new Exception("Tag '" + BaseElement.TagName + "' is not valid"); } }
public static IWebElement WaitForElementEx(this ISearchContext node, By condition, int? maxWaitMS = null, int? waitIntervalMS = null) { maxWaitMS = maxWaitMS ?? MaxWaitMS; waitIntervalMS = waitIntervalMS ?? WaitIntervalMS; DateTime finishTime = DateTime.UtcNow.AddMilliseconds(maxWaitMS.Value); do { DateTime timeAttempted = DateTime.UtcNow; try { return node.FindElement(condition); } catch (Exception) { if (timeAttempted > finishTime) { throw; } } Thread.Sleep(waitIntervalMS.Value); } while (true); }
public static IWebElement FindDisplayedElement(this IWebDriver webDriver, By by, double time) { try { { return new WebDriverWait(webDriver, TimeSpan.FromSeconds(time)) .Until<IWebElement>(d => { try { return d.FindElement(@by).Displayed ? d.FindElement(@by) : null; } catch (Exception) { return null; } }); } } catch (WebDriverTimeoutException) { Console.WriteLine("Element was not found. Timeou after: {0}", time); return null; } }
private IEnumerable<INativeElement> FindElements(By by) { var elements = _context.FindElements(by); foreach (var element in elements) yield return new WebDriverNativeElement(element); }
public IWebElement GetElement(By by) { if (Tag == null) throw new NullReferenceException("You can't call GetElement on a block without first initializing Tag."); return Tag.GetElement(by); }
public IList<IWebElement> GetElements(By by) { if (Tag == null) throw new NullReferenceException("You can't call GetElements on a block without first initializing Tag."); return Tag.FindElements(by); }
public ScrollElement(ScrollerItems item) { ImageDropName = itemsdrop[item]; ImageDragName = itemsdrag[item]; locator = itempath[item]; var wait = new WebDriverWait(Browser.GetDriver(), TimeSpan.FromMilliseconds(Convert.ToDouble(Configuration.GetTimeout()))); try { wait.Until(waiting => { try { return Browser.GetDriver().FindElement(locator).GetAttribute("style").Contains("background-image: url"); } catch (Exception) { return false; } }); } catch (WebDriverTimeoutException) { Assert.Fail("Cannot wait until image displayed"); } }
public override void setupDev1() { txtSearch = By.Id("gbqfq"); btnSearch1 = By.Id("gbqfba"); btnSearch2 = By.Id("gbqfb"); lnkAny = By.XPath(".//*[@id='rso']//a[1]"); }
/// <summary> /// Click the 'Open Vavancy' link that appears after clicking a vacancy record in the search results /// </summary> private void OpenVacancy() { var openVacancyLink = _driver.FindElement(By.LinkText("Show Applicants")); openVacancyLink.WaitAndClick(_driver); }
/// <summary> /// Click the 'Open Application' link that appears after clicking an applicant record in the search results /// </summary> private void OpenApplication() { var openApplicationLink = _driver.FindElement(By.LinkText("Open Application")); openApplicationLink.WaitAndClick(_driver); }
public ReadOnlyCollection <IWebElement> FindElements(By @by) { throw new NotSupportedException(); }
/// <summary> /// Finds the first <see cref="OpenQA.Selenium.IWebElement" /> using the specified method. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>The first matching <see cref="OpenQA.Selenium.IWebElement" /> on the current context.</returns> /// <exception cref="OpenQA.Selenium.NoSuchElementException">If no element matches the criteria.</exception> public virtual IWebElement FindElement(OpenQA.Selenium.By by) { long implictWait = GetImplicitWait(); return(FindElement(by, implictWait)); }
/// <summary> /// Finds a widget relative to the current one by traversing the qooxdoo /// widget hierarchy. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>The found widget.</returns> public virtual IWidget FindWidget(OpenQA.Selenium.By by) { IWebElement element = FindElement(by); return(Driver.GetWidgetForElement(element)); }
public static IList <Footer> Footers(this ISearchContext context, OpenQA.Selenium.By constraint = null) { return(context.Find <Footer>(constraint)); }
public IWebElement FindNonExistentElement(int timeoutInSeconds) { return(Find().Element(By.Id("RandomElement"), TimeSpan.FromSeconds(timeoutInSeconds))); }
/// <summary> /// Click the 'Open Employee Record' link that appears after clicking an employee record in the search results /// </summary> private void OpenEmployeeRecord() { var openEmployeeRecordLink = _driver.FindElement(By.LinkText("Open Employee Record")); openEmployeeRecordLink.WaitAndClick(_driver); }
/// <summary> /// Common method for click functionality. /// </summary> /// <param name="Locator">Element to perform action on.</param> public static void clickElement(OpenQA.Selenium.By Locator) { CommonProperties.commonDriver.FindElement(Locator).Click(); }
/// <summary> /// Initializes a new instance of the <see cref="T:OpenQA.Selenium.Support.Events.FindElementEventArgs" /> class. /// </summary> /// <param name="driver">The WebDriver instance used in finding elements.</param> /// <param name="element">The element that was found</param> /// <param name="method">The <see cref="T:OpenQA.Selenium.By" /> object containing the method used to find elements.</param> public FoundElementEventArgs(IWebDriver driver, IWebElement element, OpenQA.Selenium.By method) { Driver = driver; Element = element; FindMethod = method; }
public AssertionResultPage InputFixtureA() { Input().Model(Form1Fixtures.A); return(Navigate().To <AssertionResultPage>(By.CssSelector("input[type=submit]"))); }
public TResult ActionOnLocator <TResult>(By findExpression, Func <IWebElement, TResult> func, int maxWaitInSeconds = 5) { throw new NotImplementedException("Obsolete"); }
/// <summary> /// Waits to find the first matching <see cref="IWidget"/> using the specified locator. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <param name="timeoutInSeconds">The number of seconds to wait for the widget.</param> /// <returns>The first matching element on the current page.</returns> /// <exception cref="NoSuchElementException"> If no matching widget was found before the timeout elapsed </exception> /// <seealso cref="By"/> public virtual IWidget WaitForWidget(OpenQA.Selenium.By by, int timeoutInSeconds) { return(FindWidget(by, timeoutInSeconds)); }
/// <summary> /// Finds all <see cref="IWebElement"/> within the current context /// using the specified mechanism. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <returns>A <see cref="ReadOnlyCollection{IWebElement}"/> of all <see cref="IWebElement"/> /// matching the current criteria, or an empty list if nothing matches.</returns> public ReadOnlyCollection <IWebElement> FindElements(OpenQA.Selenium.By by) { return(_driver.FindElements(by)); }
public IWebElement WithPatience(By findElement, Action <IWebElement> action, int waitInSeconds = 20) { throw new NotImplementedException("Obsolete"); }
/// <summary> /// Finds a widget relative to the current one by traversing the qooxdoo /// widget hierarchy. /// </summary> /// <param name="by">The locating mechanism to use.</param> /// <param name="timeoutInSeconds">The number of seconds to wait for the widget.</param> /// <returns>The matching widget.</returns> public virtual IWidget WaitForWidget(OpenQA.Selenium.By by, long timeoutInSeconds) { IWebElement element = FindElement(by, timeoutInSeconds); return(Driver.GetWidgetForElement(element)); }
/// <summary> /// Finds the first <see cref="IWebElement" /> using the specified 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(OpenQA.Selenium.By by) { return(_driver.FindElement(by)); }
public IWebElement Element(By findExpression, TimeSpan maxWait = default(TimeSpan)) { return(Browser.ElementWithWait(d => d.FindElement(findExpression), maxWait)); }
public static IList <Fieldset> Fieldsets(this ISearchContext context, OpenQA.Selenium.By constraint = null) { return(context.Find <Fieldset>(constraint)); }
public static IList <Section> Sections(this ISearchContext context, OpenQA.Selenium.By constraint = null) { return(context.Find <Section>(constraint)); }
public static IList <Article> Articles(this ISearchContext context, OpenQA.Selenium.By constraint = null) { return(context.Find <Article>(constraint)); }
private IWebElement FindElement(OpenQA.Selenium.By by, long timeoutInSeconds) { WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(timeoutInSeconds)); return(wait.Until(IsRendered(_contentElement, by))); }
public static H1 H1(this ISearchContext context, OpenQA.Selenium.By constraint) { return(context.Find <H1>(constraint).SingleOrThrowNotFoundException()); }
public IWebElement FindElement(By @by) { throw new NotSupportedException(); }
/// <summary> /// Gets a mechanism to find elements by their tag name. /// </summary> /// <param name="tagNameToFind">The tag name to find.</param> /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns> public static new SeleniumBy TagName(string tagNameToFind) => SeleniumBy.TagName(tagNameToFind);
/// <summary> /// A condition that checks if an element is rendered. /// </summary> /// <param name="element">The element.</param> /// <param name="by">The locating mechanism to use.</param> /// <returns>.</returns> public Func <IWebDriver, IWebElement> IsRendered(IWebElement element, OpenQA.Selenium.By by) { return((driver) => { return element.FindElement(by); }); }
public IWebElement ElementWithWait(By findElement, int waitInSeconds = 20) { throw new NotImplementedException("Obsolete"); }
/// <summary> /// Gets a mechanism to find elements by an XPath query. When searching within a <see cref="IWebElement"/> /// using xpath be aware that <see cref="IWebDriver"/> follows standard conventions: a search prefixed with /// <c>"//"</c> will search the entire document, not just the children of this current node. Use <c>".//"</c> /// to limit your search to the children of this <see cref="IWebElement"/>. /// </summary> /// <param name="xpathToFind">The XPath query to use.</param> /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns> public static new SeleniumBy XPath(string xpathToFind) => SeleniumBy.XPath(xpathToFind);
public IWebElement TryFindElement(By @by) { throw new NotImplementedException("Obsolete"); }
/// <summary> /// Gets a mechanism to find elements by a partial match on their link text. /// </summary> /// <param name="partialLinkTextToFind">The partial link text to find.</param> /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns> public static new SeleniumBy PartialLinkText(string partialLinkTextToFind) => SeleniumBy.PartialLinkText(partialLinkTextToFind);