public IWebElement WaitForElementIsVisible(By locator) { _log.Log($"Waiting locator {locator} "); IWebElement element = _wait.Until(ExpectedConditions.ElementIsVisible(locator)); return(element); }
public HomePage OpenCustomer() { OpenButton.Click(); _wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.TagName("iframe"))); _wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("rotator2"))); return(new HomePage(_driver, _wait)); }
//This function search the hide record video and verify the same public void verifyingNoresultFound(IWebDriver driver, IWait <IWebDriver> iWait, string videoname) { appURL = cf.readingXMLFile("WebPortal", "Login", "startURL", "Config.xml"); driver.Navigate().GoToUrl(appURL); driver.Manage().Window.Maximize(); //wait till jquery gets completed uf.isJqueryActive(driver); iWait.Until(ExpectedConditions.ElementExists(By.Id(or.readingXMLFile("VideoLandingPage", "SearchTB", "TVWebPortalOR.xml")))); //search the required video IWebElement SearchTextField = driver.FindElement(By.Id(or.readingXMLFile("VideoLandingPage", "SearchTB", "TVWebPortalOR.xml"))); SearchTextField.SendKeys(videoname); iWait.Until(ExpectedConditions.ElementToBeClickable(By.Id(or.readingXMLFile("VideoLandingPage", "SearchIcon", "TVWebPortalOR.xml")))); //Click on searchIcon IWebElement SearchIcon = driver.FindElement(By.Id(or.readingXMLFile("VideoLandingPage", "SearchIcon", "TVWebPortalOR.xml"))); SearchIcon.Click(); uf.isJqueryActive(driver); iWait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.CssSelector("div > span#result > p"))); //verifying the video with no result found String NoResultFound = driver.FindElement(By.CssSelector("div > span#result > p")).Text; Thread.Sleep(1000); Assert.AreEqual("No result found", NoResultFound); }
static public bool WaitAjaxToLoad(IWebDriver driver, IWait <IWebDriver> wait) { bool ajaxLoaded = false; try { wait.Until(x => (long)((IJavaScriptExecutor)x).ExecuteScript("return jQuery.active") == 1); ajaxLoaded = true; Console.WriteLine("Ajax loading."); } catch (WebDriverTimeoutException) { Console.WriteLine("Timeout, No Ajax loading."); // No ajax loading ajaxLoaded = false; } if (ajaxLoaded == true) { try { wait.Until(x => (long)((IJavaScriptExecutor)x).ExecuteScript("return jQuery.active") == 0); Console.WriteLine("Javascript loading finished."); } catch (WebDriverTimeoutException) { Console.WriteLine("Timeout. Javascript loading failed."); } } return(ajaxLoaded); }
public List <string> GetColumnContents(string colName) { var columnElements = driver.FindElements(By.XPath("//tr[@class='list__header']/th")); var tableElements = driver.FindElements(By.XPath("//tr[@class='collection__item']")); var columnText = columnElements.Select((column) => column.Text).ToList(); var columnIndex = columnText.FindIndex(a => a == colName); var columnContents = new List <string>(); const string entityXPath = "//tr[contains(@class,'collection__item')]"; _driverWait.Until(driver => driver.FindElements(By.XPath(entityXPath)).Count > 0); ReadOnlyCollection <IWebElement> rowElements; foreach (var element in tableElements) { try { rowElements = element.FindElements(By.TagName("td")); } catch (StaleElementReferenceException) { // wait a second for the elements to be stable then try again System.Threading.Thread.Sleep(1000); rowElements = element.FindElements(By.TagName("td")); } var rowList = rowElements.Select((column) => column.Text).ToList(); var rowValue = rowList[columnIndex]; columnContents.Add(rowValue); } return(columnContents); }
public void sendMessageToAdmin(String msg) { iWait.Until(ExpectedConditions.ElementIsVisible((OR.GetElement("QnAManagement", "ChatText", "TVWebPortalOR.xml")))); driver.FindElement((OR.GetElement("QnAManagement", "ChatText", "TVWebPortalOR.xml"))).SendKeys(msg); Thread.Sleep(1000); executor.ExecuteScript("arguments[0].click()", driver.FindElement((OR.GetElement("QnAManagement", "ReplyButton", "TVWebPortalOR.xml")))); }
public void ValidateSuccessfulTwitterSend() { // The alert message will popup and fade. IWebElement sentMessage = _shortWait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("header div.passive_alert"))); Assert.AreEqual("Message has been sent!", sentMessage.Text); }
/* Compares the url of the driver to the url of this page object after stripping * any trailing whitespaces and forward slashes. */ public BasePage AssertOnPage() { var thisUrl = Url.Trim('/'); driverWait.Until(driver => driver.Url.Trim('/') == thisUrl); Assert.Equal(driver.Url.Trim('/'), thisUrl); return(this); }
public void EnterMessage(string message) { IWebElement tweetTextbox = _wait.Until( ExpectedConditions.ElementIsVisible(By.CssSelector("form#compose-form article.messagetext textarea"))); tweetTextbox.SendKeys(message); }
private static bool DomState(IWebDriver driver, ICapabilities capabilities, IWait <IWebDriver> wait) { IJavaScriptExecutor js = driver as IJavaScriptExecutor; if (capabilities.BrowserName.Equals("Firefox")) { return((bool)wait.Until(page => js.ExecuteScript("return (document.readyState == 'complete' || (!!window.jQuery && window.jQuery.active == 0))"))); } else { return((bool)wait.Until(page => js.ExecuteScript("return (document.readyState == 'complete' && window.jQuery.active == 0)"))); } }
public void ValidateConversionResult(string destAmount, string destUnit) { // Make sure the correct amount is displayed IWebElement amountElement = _defaultWait.Until(d => _widgetElement.FindElement(By.CssSelector("input#uc_rv"))); Assert.AreEqual(destAmount, amountElement.GetAttribute("value")); // Make sure the correct unit is selected IWebElement selectedOption = _defaultWait.Until(d => _widgetElement.FindElement(By.CssSelector("select#uc_rt option:checked"))); Assert.IsNotNull(selectedOption); Assert.AreEqual(destUnit.ToLower(), selectedOption.Text.ToLower()); }
internal void GoToUrl(string URL) { try { driver.Navigate().GoToUrl(URL); iWait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete")); #region Manually click on Advance in IE for unsecure certificates and then click on more information tab //driver.FindElement(By.CssSelector("div#certErrorAndCaptivePortalButtonContainer > button#advancedButton")).Click(); //driver.FindElement(By.LinkText("More information")).Click(); //IWebElement WebPageNotRecommended = driver.FindElement(By.LinkText("Go on to the webpage (not recommended)")); //Thread.Sleep(2000); //WebPageNotRecommended.Click(); #endregion if (Convert.ToBoolean(browser.SelectBrowser(BrowserCollection.ie.ToString(), "Browser.xml")) == true) { if (driver.Url.Contains("https")) { driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()"); } Thread.Sleep(3000); } } catch (Exception error) { Logger.log.Error("Browser could not navigate to the specified url properly"); Logger.log.Error(error); } }
/// <summary> /// General Purpose Wait for FindElements to meet a given condition. /// </summary> /// <param name="wait"></param> /// <param name="findFunction"></param> /// <param name="conditionFunction"></param> /// <param name="conditionDescription"></param> /// <returns></returns> /// <exception cref="NoSuchElementException"></exception> /// <exception cref="WebDriverTimeoutException"></exception> protected ReadOnlyCollection <IWebElement> FindElementsWithWait( IWait <IWebDriver> wait, Func <ReadOnlyCollection <IWebElement> > findFunction, Func <ReadOnlyCollection <IWebElement>, bool> conditionFunction, string conditionDescription) { try { return(wait.Until(d => { ReadOnlyCollection <IWebElement> returnedElements = findFunction.Invoke(); if (conditionFunction(returnedElements)) { throw new NoSuchElementException(); } return returnedElements; })); } catch (WebDriverTimeoutException ex) { throw new WebDriverTimeoutException( $"{ex.Message}: {conditionDescription} were found in the searched context.", ex); } }
public void ValidateSearchResults() { IWebElement searchResultsHeader = _defaultWait.Until(d => { var results = d.FindElements(By.CssSelector("h2")); return(results.FirstOrDefault(h => h.GetAttribute("innerText") == "Search Results")); }); Assert.IsNotNull(searchResultsHeader); IWebElement resultsDiv = _defaultWait.Until( ExpectedConditions.ElementExists(By.CssSelector($"div[data-async-context=\"query:{_searchTerm}\"]"))); Assert.IsNotEmpty(resultsDiv.Text); }
public void CloseBanner() { wait.Until( ExpectedConditions.ElementToBeClickable( _closeBannerButton)) .Click(); }
private static PriceInfo[] ParseBodenPrices(IWebDriver driver, IWait <IWebDriver> wait) { IList <PriceInfo> priceInfos = new List <PriceInfo>(); ReadOnlyCollection <IWebElement> sizeList = driver.FindElement(By.Id("pdpBuyingPanel_SizeChart")).FindElements(By.CssSelector("*")); if (sizeList.Count > 0) { foreach (IWebElement sizeItem in sizeList) { ReadOnlyCollection <IWebElement> anchors = sizeItem.FindElements(By.TagName("a")); if (anchors.Count > 0) { IWebElement sizeButton = anchors[0]; string sizeString = sizeButton.Text; try { // With a small window, the element might not come into view. In theory we should move to the element then click. // However, Actions does not seem to work in this case. //Actions actions = new Actions(driver); //actions.MoveToElement(sizeButton).Click().Perform(); // Altenatively, we start with a large enough screen and then Click() function should work. But this is not ideal. //sizeButton.Click(); // Executing a javascript seems to work well regardless of screen size. IJavaScriptExecutor ex = (IJavaScriptExecutor)driver; ex.ExecuteScript("arguments[0].click();", sizeButton); } catch (Exception e) { Console.WriteLine("exception: {0}", e); continue; } wait.Until(x => (string)((IJavaScriptExecutor)x).ExecuteScript("return document.readyState") == "complete"); IWebElement priceElement = driver.FindElements(By.ClassName("pdpAddToBagPrice")).First(); string priceString = priceElement.Text; ReadOnlyCollection <IWebElement> stockElements = driver.FindElements(By.ClassName("pdpStockAvailability")).First().FindElements(By.CssSelector("*")); string stockString = "Unknown"; foreach (IWebElement stockElement in stockElements) { string className = stockElement.GetAttribute("class"); if (!className.Contains("ng-hide") || className.Contains("ng-hide-remove")) { stockString = stockElement.Text; } } string priceNumberString = new string(priceString.Where(x => Char.IsDigit(x) || x == '.').ToArray()); Decimal price = priceNumberString.Length > 0 ? Convert.ToDecimal(priceNumberString) : -1; priceInfos.Add(new PriceInfo { Size = sizeString.Trim(), Price = price, PriceCN = GBP2RMB(price), Stock = stockString.Trim() }); } } } return(priceInfos.ToArray()); }
public void DynamicControlTests() { driver.Navigate().GoToUrl("http://the-internet.herokuapp.com/dynamic_controls"); IWebElement removeButton = driver.FindElement(By.XPath("//div[@id='checkbox']/following::button[1]")); removeButton.Click(); string actualPText = driver.FindElement(By.Id("message")).Text; string expectedPText = "It's gone!"; Assert.AreEqual(expectedPText, actualPText); IWebElement addButton = driver.FindElement(By.XPath("//form[@id='checkbox-example']/child::button")); bool visible = addButton.Displayed; if (visible == true) { addButton.Click(); } else { wait.Until(ExpectedConditions.ElementToBeClickable(addButton)); } string expectedPTextAfterChanging = "It's back!"; string actualPTextAfterChanging = driver.FindElement(By.Id("message")).Text; Assert.AreEqual(expectedPTextAfterChanging, actualPTextAfterChanging); }
public void ContextMenutest() { IWebElement contextMenulink = driver.FindElement(By.LinkText("Context Menu")); contextMenulink.Click(); IWebElement contextMenu = driver.FindElement(By.XPath("//div[@id='hot-spot']")); actions = new Actions(driver); actions.ContextClick(contextMenu).Perform(); wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.AlertIsPresent()); IAlert alert = driver.SwitchTo().Alert(); try { Assert.IsTrue(alert != null); } catch (NoAlertPresentException) { } alert.Accept(); try { driver.SwitchTo().Alert(); } catch (NoAlertPresentException) { Assert.Pass("Alert is not present on the page"); } }
private static bool CheckElementExists(IWebDriver webDriver, string elementToFind, ByElementType checkType, int timeinSeconds = TimeinSecond) { var elementFound = false; try { _wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeinSeconds)); var by = CommonPageHelper.GetByElement(checkType, elementToFind); elementFound = _wait.Until(ExpectedConditions.ElementExists(by)) != null; } catch (Exception ex) { Console.WriteLine("Exception Occured For Id:{0}, ErrorMessage:{1}, Method: {2}", elementToFind, ex.InnerException, "CommonPage.CheckElementExists"); } return(elementFound); }
//This function search the required video and verify the same public void TVWeb_001_SearchVideofunctionality(IWebDriver driver, IWait <IWebDriver> iWait, string videoname, string GUID_Admin) { appURL = cf.readingXMLFile("WebPortal", "Login", "startURL", "Config.xml"); driver.Navigate().GoToUrl(appURL); driver.Manage().Window.Maximize(); //wait till jquery gets completed uf.isJqueryActive(driver); iWait.Until(ExpectedConditions.ElementExists(By.Id(or.readingXMLFile("VideoLandingPage", "SearchTB", "TVWebPortalOR.xml")))); //search the required video IWebElement SearchTextField = driver.FindElement(By.Id(or.readingXMLFile("VideoLandingPage", "SearchTB", "TVWebPortalOR.xml"))); SearchTextField.SendKeys(videoname); iWait.Until(ExpectedConditions.ElementToBeClickable(By.Id(or.readingXMLFile("VideoLandingPage", "SearchIcon", "TVWebPortalOR.xml")))); //Click on searchIcon IWebElement SearchIcon = driver.FindElement(By.Id(or.readingXMLFile("VideoLandingPage", "SearchIcon", "TVWebPortalOR.xml"))); SearchIcon.Click(); uf.isJqueryActive(driver); //verifying the search result IList <IWebElement> videoSearchList = (IList <IWebElement>)driver.FindElement(By.Id(or.readingXMLFile("VideoLandingPage", "SearchResult", "TVWebPortalOR.xml"))).FindElements(By.ClassName(or.readingXMLFile("VideoLandingPage", "SearchResultRecord", "TVWebPortalOR.xml"))); //gettting the search result details foreach (IWebElement currentSearchrecord in videoSearchList) { IWebElement searchresultDetails = driver.FindElement(By.CssSelector(or.readingXMLFile("VideoLandingPage", "SearchResultDetails", "TVWebPortalOR.xml"))); // //getting video Title frm search result String webvideoTitle = searchresultDetails.Text.Trim(); if (webvideoTitle.Equals(videoname)) { String videoID_Web = searchresultDetails.GetAttribute("data-videono"); String GUID_Web = searchresultDetails.GetAttribute("data-videoid"); //verifying the Video Guid match on webportal with admin portal Assert.AreEqual(GUID_Admin, GUID_Web); break; } } }
/// <summary> /// Wait for page load to complete /// </summary> /// <param name="p_Timeout"></param> public static void WaitForPageLoadComplete(int p_Timeout = 5) { Driver.Manage().Timeouts().PageLoad = new TimeSpan(p_Timeout * 10000000); // 1 tick = one 10 millionth of a second so multiply to resolve back IWait <IWebDriver> wait = GetWaitDriver(p_Timeout); wait.Until(p_Driver => ((IJavaScriptExecutor)Driver).ExecuteScript("return document.readyState").Equals("complete")); }
public void verifyAwardpage() { iWait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("mat-select-value-text"))); Thread.Sleep(2000); string award = driver.FindElement(By.ClassName("edit-profile-title")).Text; Assert.AreEqual("Awards and Recognitions", award); }
public void verifyWorkExppage() { iWait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("mat-select-value-text"))); Thread.Sleep(2000); string WorkExp = driver.FindElement(By.ClassName("edit-profile-title")).Text; Assert.AreEqual("Work Experience", WorkExp); }
public void clickOnNext() { Thread.Sleep(2000); iWait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.btn.onboarding-step.onbaording-top-nav.text-right"))); driver.FindElement(By.CssSelector("button.btn.onboarding-step.onbaording-top-nav.text-right")).Click(); //int count = driver.FindElements(nextBtn).Count; // driver.FindElements(nextBtn)[1].Submit(); // w.Click(); }
//This function click on login link and click on registration link public void RegistrationPage() { driver.Navigate().GoToUrl(appURL); //clicking on Login button iWait.Until(ExpectedConditions.ElementToBeClickable(By.LinkText(OR.readingXMLFile("NonIETMemberRegistration", "LoginLink", "TVWebPortalOR.xml")))); element = driver.FindElement(By.LinkText(OR.readingXMLFile("NonIETMemberRegistration", "LoginLink", "TVWebPortalOR.xml"))); executor.ExecuteScript("arguments[0].click();", element); //clicking on Registration link iWait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); iWait.Until(ExpectedConditions.ElementToBeClickable(By.LinkText(OR.readingXMLFile("NonIETMemberRegistration", "RegistrationLink", "TVWebPortalOR.xml")))); element = driver.FindElement(By.LinkText(OR.readingXMLFile("NonIETMemberRegistration", "RegistrationLink", "TVWebPortalOR.xml"))); executor.ExecuteScript("arguments[0].click();", element); }
public ManufacturerPage OpenManufacturerPage(string manufacturer) { var menuItems = _currentPage.Menu.OpenMenu("Бренды"); _wait.Until(ExpectedConditions.ElementIsVisible( By.CssSelector($"li.megamenu-parent-block a.megamenu-parent-img img[title=\"{manufacturer}\"]"))); var menuItem = menuItems.FirstOrDefault(item => item.Image.GetAttribute("title") == manufacturer); if (menuItem == null) { throw new Exception($"Could not find item for manufacturer '{manufacturer}' in brands menu"); } menuItem.Image.Click(); return((ManufacturerPage)(_currentPage = ManufacturerPage.WaitForPage(_driver))); }
/// <summary> /// The inverse of Until(...). Will wait while a statement is true. /// </summary> /// <param name="wait"></param> /// <param name="condition"></param> /// <returns></returns> public static bool While(this IWait <IWebDriver> wait, Func <IWebDriver, bool> condition) { if (condition == null) { throw new ArgumentNullException(nameof(condition)); } return(wait.Until(d => !condition(d))); }
public void RedirectToHelpInstitution() { uf.isJqueryActive(driver); iWait.Until(ExpectedConditions.ElementIsVisible((OR.GetElement("Chrome_CMS", "HelpDestopButton", "TVWebPortalOR.xml")))); //Click on Help dropdown driver.FindElement((OR.GetElement("Chrome_CMS", "HelpDestopButton", "TVWebPortalOR.xml"))).Click(); // Thread.Sleep(2000); //click on Institution under IETTv help iWait.Until(ExpectedConditions.ElementIsVisible((OR.GetElement("Chrome_CMS", "ItemContainer", "TVWebPortalOR.xml")))); IList <IWebElement> help = driver.FindElement((OR.GetElement("Chrome_CMS", "ItemContainer", "TVWebPortalOR.xml"))).FindElements(OR.GetElement("Chrome_CMS", "InstitutionHelp", "TVWebPortalOR.xml")); executor.ExecuteScript("arguments[0].click()", help[0].FindElement(By.TagName("a"))); Console.WriteLine("Clicked on Institution"); }
public static void Until <T, TResult>(this IWait <T> wait, Func <T, TResult> condition, string message) { try { wait.Until(condition); } catch (Exception ex) { throw new Exception(message, ex); } }
public void LoginToAliExpress(Login login) { bool isAdClosed = false; try { WaitUtilities.WaitForElementNTimes(driver, adsCloseButtonLocator, TimeSpan.FromSeconds(5), 3); Click(AdsCloseButton); WaitUtilities.WaitForElementNTimes(driver, newUserAdNotificationLocator, TimeSpan.FromSeconds(5), 3); isAdClosed = true; } catch (NoSuchElementException e) { Console.WriteLine("DEBUG: Could not locate ad: " + e.Message); } WaitUtilities.WaitForElementNTimes(driver, goToGlobalSiteLinkLocator, TimeSpan.FromSeconds(5), 3); wait.Until(ExpectedConditions.ElementToBeClickable(goToGlobalSiteLinkLocator)); Click(GoToGlobalSiteLink); if (!isAdClosed) { try { WaitUtilities.WaitForElementNTimes(driver, adsCloseButtonLocator, TimeSpan.FromSeconds(5), 3); Click(AdsCloseButton); WaitUtilities.WaitForElementNTimes(driver, newUserAdNotificationLocator, TimeSpan.FromSeconds(5), 3); isAdClosed = true; } catch (NoSuchElementException e) { Console.WriteLine("DEBUG: Could not locate ad: " + e.Message); } } WaitUtilities.WaitForElementNTimes(driver, signInButtonLocator, TimeSpan.FromSeconds(5), 3); Click(SignInButton); WaitUtilities.WaitForElementNTimes(driver, aliExpressLoginFormLocator, TimeSpan.FromSeconds(5), 3); driver.SwitchTo().Frame(AliExpressLoginForm); WaitUtilities.WaitForElementNTimes(driver, loginFieldLocator, TimeSpan.FromSeconds(5), 3); SendText(LoginField, login.login); WaitUtilities.WaitForElementNTimes(driver, passwordFieldLocator, TimeSpan.FromSeconds(5), 3); SendText(PasswordField, login.password); WaitUtilities.WaitForElementNTimes(driver, loginSubmitButtonLocator, TimeSpan.FromSeconds(5), 3); Click(LoginSubmitButton); }
/// <summary> /// Wait until element is actually displayed in the DOM /// </summary> /// <param name="wait"></param> /// <param name="webElement"></param> public static void WaitForWebElementDisplayed(IWait<IWebDriver> wait, IWebElement webElement) { wait.Until(x => webElement.Displayed); }
/// <summary> /// Wait until element is enabled /// </summary> /// <param name="wait"></param> /// <param name="webElement"></param> public static void WaitForWebElementEnabled(IWait<IWebDriver> wait, IWebElement webElement) { wait.Until(x => webElement.Enabled); }