/// <summary> /// Verify the presence of a hyperlink element on a web page by matching text within the element. /// </summary> /// <param name="driver"> /// Reference to a Selenium Web driver. /// </param> /// <param name="timeout"> /// Maximum amount of time to wait for the specified element to become available. /// </param> /// <param name="title"> /// The title to match. /// </param> /// <param name="text"> /// The text to match. /// </param> /// <param name="position"> /// The position of the element on the page. /// </param> public static void VerifyHyperlinkElementExistence(IWebDriver driver, TimeSpan timeout, string title, string text, int position) { string xPath = $"//*[(self::a"; if (!string.IsNullOrEmpty(title)) { xPath += " and @title='{title}'"; } if (!string.IsNullOrEmpty(text)) { xPath += $" and (normalize-space(text())) = '{text}'"; } xPath += ")]"; if (position > 0) { xPath = "(" + xPath; xPath += $")[{position}]"; } var wait = new WebDriverWait(driver, timeout); ReadOnlyCollection <IWebElement> elements = wait.Until( SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath(xPath))); if (elements.Count > 1) { throw new MultipleElementsMatchedException(elements.Count, $"XPath '{xPath}' matched more than one element."); } SeleniumTestUtils.HighlightElement(driver, elements[0]); }
/// <summary> /// Get the configuration directory name from the test configuration file. /// </summary> /// <returns></returns> public static string GetConfigDir() { if (string.IsNullOrEmpty(configDir)) { string jsonFilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cfg", TestUtils.GetEnvValue(EnvVars.TEST_CFG_FILENAME))); configDir = SeleniumTestUtils.GetTestArgs(jsonFilePath)[0].ConfigDir; } return(configDir); }
/// <summary> /// Wait for the specified Web element to become clickable. /// </summary> /// <param name="driver"> /// Reference to a Selenium Web driver. /// </param> /// <param name="timeout"> /// Maximum time to wait for the specified element to become clickable. /// </param> /// <param name="element"> /// Reference to a Web element. /// </param> public static void Click(IWebDriver driver, TimeSpan timeout, IWebElement element) { WaitForElementToBeClickable(driver, timeout, element); SeleniumTestUtils.HighlightElement(driver, element); Actions actions = new Actions(driver); actions.MoveToElement(element); actions.Click(element); actions.Perform(); }