)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » WebDriverExtensions ()

Public general use code classes and xml files that we've compiled and used over the years:

    1: using System;
    2: using OpenQA.Selenium;
    3: using OpenQA.Selenium.Support.UI;
    4:  
    5: ////////////////////////////////////////////////////////////////////////////
    6:  
    7: /// <summary publish="true">
    8: ///
    9: /// </summary>
   10: /// 
   11: /// <remarks> 
   12: /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   13: ///
   14: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   15: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   16: ///
   17: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   19: /// 
   20: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   21: /// 
   22: /// Copyright notice: This notice may not be removed or altered from any source distribution.
   23: /// </remarks> 
   24: public static class WebDriverExtensions
   25: {
   26:     public static IWebElement FindElement(this IWebDriver webDriver, By by, int timeoutInSeconds)
   27:     {
   28:         TimeSpan timeSpan = TimeSpan.FromSeconds(timeoutInSeconds);
   29:         IWebElement webElement = null;
   30:  
   31:         try
   32:         {
   33:             WebDriverWait wait = new WebDriverWait(webDriver, timeSpan);
   34:  
   35:             webElement = wait.Until(d =>
   36:             {
   37:                 try
   38:                 {
   39:                     return d.FindElement(by);
   40:                 }
   41:                 catch (NoSuchElementException ex)
   42:                 {
   43:                     return null;
   44:                 }
   45:             });
   46:  
   47:         }
   48:         catch (WebDriverTimeoutException)
   49:         {
   50:             //Console.WriteLine("Please fail WebDriverTimeoutException");
   51:         }
   52:         catch (NoSuchElementException)
   53:         {
   54:             //Console.WriteLine("Please fail NoSuchElementException");
   55:         }
   56:  
   57:         return webElement;
   58:     }
   59: }
   60:  
   61: ////////////////////////////////////////////////////////////////////////////
   62: ////////////////////////////////////////////////////////////////////////////