OpenQA.Selenium.By.XPath C# (CSharp) Méthode

XPath() public static méthode

Gets a mechanism to find elements by an XPath query.
public static XPath ( string xpathToFind ) : By
xpathToFind string The XPath query to use.
Résultat By
        public static By XPath(string xpathToFind)
        {
            if (xpathToFind == null)
            {
                throw new ArgumentNullException("xpathToFind", "Cannot find elements when the XPath expression is null.");
            }

            By by = new By();
            by.findElementMethod = (ISearchContext context) => ((IFindsByXPath)context).FindElementByXPath(xpathToFind);
            by.findElementsMethod =
                (ISearchContext context) => ((IFindsByXPath)context).FindElementsByXPath(xpathToFind);

            by.description = "By.XPath: " + xpathToFind;
            return by;
        }

Usage Example

Exemple #1
0
        public void BookIntervalFromNotBooked(string courtNumber)
        {
            var startTimeHour = Convert.ToInt32(DateTime.Now.ToString("HH"));

            startTimeHour = startTimeHour + 1;
            var startTimeMinutes = DateTime.Now.ToString("mm");
            var startTimeSeconds = DateTime.Now.ToString("ss");

            Console.WriteLine(startTimeHour + ":" + startTimeMinutes + ":" + startTimeSeconds);
            switch (courtNumber)
            {
            case "Court1":
                driver.FindElement(By.XPath(
                                       "//*[@id='book-by-date-view']/div/div[2]/div[2]/ul/li[1]/div/div/div[2]/div/div[" +
                                       startTimeHour + "]")).Click();
                break;

            case "Court2":
                driver.FindElement(By.XPath(
                                       "//*[@id='book-by-date-view']/div/div[2]/div[2]/ul/li[2]/div/div/div[2]/div/div[" +
                                       startTimeHour + "]")).Click();
                break;

            case "Court3":
                driver.FindElement(By.XPath(
                                       "//*[@id='book-by-date-view']/div/div[2]/div[2]/ul/li[3]/div/div/div[2]/div/div[" +
                                       startTimeHour + "]")).Click();
                break;
            }
        }
All Usage Examples Of OpenQA.Selenium.By::XPath