• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IWebDriver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IWebDriver的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver类的具体用法?C# IWebDriver怎么用?C# IWebDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IWebDriver类属于命名空间,在下文中一共展示了IWebDriver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Logout

        public void Logout(IWebDriver driverToUse = null)
        {
            if (driverToUse == null)
                driverToUse = driver;

            driverToUse.FindElement(By.Id("LoginStatus1")).Click();
        }
开发者ID:NathanGloyn,项目名称:Selenium-UI-Testing,代码行数:7,代码来源:When_viewing_orders.cs


示例2: TrySetupSteps

        private void TrySetupSteps(DriverType driverType, SeleniteTest test, IWebDriver webDriver)
        {
            if (test.TestCollection.SetupSteps.IsNullOrNotAny())
                return;

            var fileName = String.IsNullOrWhiteSpace(test.TestCollection.SetupStepsFile)
                ? test.TestCollection.ResolvedFile
                : test.TestCollection.SetupStepsFile;

            foreach (var pair in _setupStepsMap)
            {
                if (pair.Key.Target != webDriver)
                    continue;

                if (pair.Value.Any(f => String.Equals(f, fileName, StringComparison.InvariantCultureIgnoreCase)))
                    return;
            }

            foreach (var setupStep in test.TestCollection.SetupSteps)
                _testService.ExecuteTest(webDriver, driverType, setupStep, true);

            var weakReference = new WeakReference(webDriver);
            var testFiles = new List<string> { fileName };
            _setupStepsMap.Add(weakReference, testFiles);
        }
开发者ID:MGetmanov,项目名称:Selenite,代码行数:25,代码来源:SeleniteFixture.cs


示例3: HandleSeleneseCommand

        protected override object HandleSeleneseCommand(IWebDriver driver, string pattern, string ignored)
        {
            string text = string.Empty;
            IWebElement body = driver.FindElement(By.XPath("/html/body"));
            IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
            if (executor == null)
            {
                text = body.Text;
            }
            else
            {
                text = JavaScriptLibrary.CallEmbeddedHtmlUtils(driver, "getTextContent", body).ToString();
            }

            text = text.Trim();

            string strategyName = "implicit";
            string use = pattern;

            if (TextMatchingStrategyAndValueRegex.IsMatch(pattern))
            {
                Match textMatch = TextMatchingStrategyAndValueRegex.Match(pattern);
                strategyName = textMatch.Groups[1].Value;
                use = textMatch.Groups[2].Value;
            }

            ITextMatchingStrategy strategy = textMatchingStrategies[strategyName];
            return strategy.IsAMatch(use, text);
        }
开发者ID:hugs,项目名称:selenium,代码行数:29,代码来源:IsTextPresent.cs


示例4: GetElementXPath

        public static string GetElementXPath(IWebElement webElement, IWebDriver webDriver)
        {
            IJavaScriptExecutor jsExec = webDriver as IJavaScriptExecutor;
            return (string)jsExec.ExecuteScript(
            @"
            function getPathTo(element) {
            if (element === document.body)
            return '/html/' + element.tagName.toLowerCase();

            var ix = 0;
            var siblings = element.parentNode.childNodes;
            for (var i = 0; i < siblings.length; i++) {
            var sibling = siblings[i];
            if (sibling === element)
            {
            return getPathTo(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (ix + 1) + ']';
            }
            if (sibling.nodeType === 1 && sibling.tagName === element.tagName)
            ix++;
            }
            }

            var element = arguments[0];
            var xpath = '';
            xpath = getPathTo(element);
            return xpath;
            ", webElement);
        }
开发者ID:sergueik,项目名称:swd-recorder-appium,代码行数:28,代码来源:JavaScriptUtils.cs


示例5: LaunchBrowser

        public IWebDriver LaunchBrowser(Browser browser)
        {
            switch (browser)
            {
                case Browser.IE:
                    driver = StartIEBrowser();
                    break;
                case Browser.Chrome:
                    driver = StartChromeBrowser();
                    break;
                case Browser.Safari:
                    driver = StartSafariBrowser();
                    break;
                case Browser.Firefox:
                default:
                    driver = StartFirefoxBrowser();
                    break;
            }

            driver.Manage().Cookies.DeleteAllCookies();
            SetBrowserSize();
            var eDriver = new EventedWebDriver(driver);

            return eDriver.driver;
        }
开发者ID:tokarthik,项目名称:ProtoTest.Golem,代码行数:25,代码来源:WebDriverBrowser.cs


示例6: Run

        public void Run(IWebDriver webDriver, Step step)
        {
            var e = ((ElementHasStyleStep)step);
            try
            {
                var element = ElementHelper.GetVisibleElement(webDriver, e.Element);

                string style = element.GetAttribute("style");
                var styles = style.Split(';').Select(x =>
                                                     {
                                                         var parts = x.Replace(" ", "").Split(':');
                                                         if (parts.Length != 2) return null;
                                                         return new Style(parts[0], parts[1]);
                                                     }).Where(x => x != null).ToList();

                if (styles.All(x => x.Key != e.StyleKey))
                    throw new StepException(string.Format("The element '{0}' did not have the '{1}' style.", e.Element,
                        e.StyleKey));

                if (!styles.Any(x => x.Key == e.StyleKey && x.Value == e.StyleValue))
                    throw new StepException(
                        string.Format("The element '{0}' had the '{1}' style, but it's value was not '{2}'.", e.Element,
                            e.StyleKey, e.StyleValue));
            }
            catch (NoSuchElementException ex)
            {
                throw new StepException(string.Format("The document does not contain an element that matches '{0}'.",
                    e.Element));
            }
        }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:30,代码来源:AssertElementHasStyleBrowserStepStrategy.cs


示例7: TouchActions

        /// <summary>
        /// Initializes a new instance of the <see cref="TouchActions"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
        public TouchActions(IWebDriver driver)
            : base(driver)
        {
            IHasTouchScreen touchScreenDriver = driver as IHasTouchScreen;
            if (touchScreenDriver == null)
            {
                IWrapsDriver wrapper = driver as IWrapsDriver;
                while (wrapper != null)
                {
                    touchScreenDriver = wrapper.WrappedDriver as IHasTouchScreen;
                    if (touchScreenDriver != null)
                    {
                        break;
                    }

                    wrapper = wrapper.WrappedDriver as IWrapsDriver;
                }
            }

            if (touchScreenDriver == null)
            {
                throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasTouchScreen.", "driver");
            }

            this.touchScreen = touchScreenDriver.TouchScreen;
        }
开发者ID:kaushik9k,项目名称:Selenium2,代码行数:30,代码来源:TouchActions.cs


示例8: HandleSeleneseCommand

        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            string tableString = string.Empty;

            if (!TableParts.IsMatch(locator))
            {
                throw new SeleniumException("Invalid target format. Correct format is tableName.rowNum.columnNum");
            }

            Match tableMatch = TableParts.Match(locator);
            string tableName = tableMatch.Groups[0].Value;
            long row = int.Parse(tableMatch.Groups[1].Value, CultureInfo.InvariantCulture);
            long col = int.Parse(tableMatch.Groups[2].Value, CultureInfo.InvariantCulture);

            IWebElement table = finder.FindElement(driver, tableName);

            string script =
                "var table = arguments[0]; var row = arguments[1]; var col = arguments[2];" +
                "if (row > table.rows.length) { return \"Cannot access row \" + row + \" - table has \" + table.rows.length + \" rows\"; }" +
                "if (col > table.rows[row].cells.length) { return \"Cannot access column \" + col + \" - table row has \" + table.rows[row].cells.length + \" columns\"; }" +
                "return table.rows[row].cells[col];";

            object returnValue = JavaScriptLibrary.ExecuteScript(driver, script, table, row, col);
            IWebElement elementReturned = returnValue as IWebElement;
            if (elementReturned != null)
            {
                tableString = ((IWebElement)returnValue).Text.Trim();
            }
            else
            {
                throw new SeleniumException(returnValue.ToString());
            }

            return tableString;
        }
开发者ID:zerodiv,项目名称:CTM-Windows-Agent,代码行数:35,代码来源:GetTable.cs


示例9: ManageQueueSection

 ManageQueueSection(
     IWebDriver          webBrowserDriver)
         : base(webBrowserDriver)
 {
     this.QueueInformation = new QueueInformationSection(webBrowserDriver);
     this.QueueClient      = new QueueClientSection(webBrowserDriver);
 }
开发者ID:eesee,项目名称:slinqy,代码行数:7,代码来源:ManageQueueSection.cs


示例10: Selectanoption

 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);
 }
开发者ID:TejaVellanki,项目名称:PlatformAutomationTestFramework,代码行数:7,代码来源:driverdefining.cs


示例11: SearchPage

 public SearchPage(IWebDriver driver)
 {
     this.driver = driver;
     Boolean isPresent = driver.FindElement(By.CssSelector("#btnFTPOutputFile")).Size > 0;
     if (isPresent == false)
         throw new NoSuchElementException("This is not the Search page");               
 }
开发者ID:rohanbaraskar,项目名称:PageObjects,代码行数:7,代码来源:SearchPage.cs


示例12: DestroyVisualSearch

        internal static void DestroyVisualSearch(IWebDriver webDriver)
        {
            MyLog.Write("DestroyVisualSearch: Started");
            IJavaScriptExecutor jsExec = webDriver as IJavaScriptExecutor;

            string[] JavaSCriptObjectsToDestroy = new string[]
            {
                "document.SWD_Page_Recorder",
                "document.Swd_prevActiveElement",
                "document.swdpr_command",
            };

            StringBuilder deathBuilder = new StringBuilder();

            foreach (var sentencedToDeath in JavaSCriptObjectsToDestroy)
            {

                deathBuilder.AppendFormat(@" try {{ delete {0}; }} catch (e) {{ if (console) {{ console.log('ERROR: |{0}| --> ' + e.message)}} }} ", sentencedToDeath);
            }

            if (IsVisualSearchScriptInjected(webDriver))
            {
                MyLog.Write("DestroyVisualSearch: Scripts have been injected previously. Kill'em all!");
                jsExec.ExecuteScript(deathBuilder.ToString());
            }

            MyLog.Write("DestroyVisualSearch: Finished");
        }
开发者ID:sergueik,项目名称:swd-recorder-appium,代码行数:28,代码来源:JavaScriptUtils.cs


示例13: HandleSeleneseCommand

        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="driver">The driver used to execute the command.</param>
        /// <param name="locator">The first parameter to the command.</param>
        /// <param name="value">The second parameter to the command.</param>
        /// <returns>The result of the command.</returns>
        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            UserLookupStrategy strategy = new UserLookupStrategy(value);
            this.finder.AddStrategy(locator, strategy);

            return null;
        }
开发者ID:v4viveksharma90,项目名称:selenium,代码行数:14,代码来源:AddLocationStrategy.cs


示例14: CreateCustomerPage

 public CreateCustomerPage(IWebDriver driver) : base(driver)
 {
     if (!driver.PageSource.Contains("Server Error") && driver.Title != "Nuovo cliente")
     {
         throw new ArgumentException("This is not the create customer page: " + driver.Title);
     }
 }
开发者ID:immaginario,项目名称:Pallino.DailyActivities,代码行数:7,代码来源:CreateCustomerPage.cs


示例15: HandleSeleneseCommand

 /// <summary>
 /// Handles the command.
 /// </summary>
 /// <param name="driver">The driver used to execute the command.</param>
 /// <param name="locator">The first parameter to the command.</param>
 /// <param name="value">The second parameter to the command.</param>
 /// <returns>The result of the command.</returns>
 protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
 {
     StringBuilder builder = new StringBuilder();
     this.mutator.Mutate(locator, builder);
     ((IJavaScriptExecutor)driver).ExecuteScript(builder.ToString());
     return null;
 }
开发者ID:JoeHe,项目名称:selenium,代码行数:14,代码来源:RunScript.cs


示例16: TakeScreenshot

 public void TakeScreenshot(IWebDriver driver, string path)
 {
     ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
     Screenshot screenshot = screenshotDriver.GetScreenshot();
     screenshot.SaveAsFile(path, System.Drawing.Imaging.ImageFormat.Png);
     screenshot.ToString();
 }
开发者ID:photon-infotech,项目名称:sharepoint-hw,代码行数:7,代码来源:AllTest.cs


示例17: BaseTestInitialize

 public void BaseTestInitialize(IWebDriver initialDriver, string baseUri, int timeout)
 {
     this.Driver = initialDriver;
     this.BaseUri = baseUri;
     this.Timeout = timeout;
     this.Wait = new WebDriverWait(initialDriver, TimeSpan.FromSeconds(timeout));
 }
开发者ID:,项目名称:,代码行数:7,代码来源:


示例18: GetDriver

 private void GetDriver()
 {
     _driver = (IWebDriver)Registry.hashTable["driver"]; //забираем из хештаблицы сохраненный ранее драйвер
     _driver.Navigate().GoToUrl(Paths.UrlCreatePk); //заходим по ссылке
     _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
     //ставим ожидание в 10 сек на случай, если страница медленно грузится и нужные эл-ты появятся не сразу
 }
开发者ID:Evening89,项目名称:Task,代码行数:7,代码来源:GoodsCreatePk_Controller.cs


示例19: TestCleanup

        public void TestCleanup()
        {
            if (Properties.Settings.Default.BROWSER == BrowserType.Ie)
            {
                driver.Quit();
                driver = null;
            }

            try
            {
                if (MyBook.Name != "")
                {
                    MyBook.Save();
                    MyBook.Close();
                }
                if (MyApp.Name != "")
                {
                    MyApp.Quit();
                }
            }catch
            { }

            KillProcess("EXCEL");
            KillProcess("IEDriverServer");
            KillProcess("iexplore");
        }
开发者ID:pjagga,项目名称:SeleniumMSTestVS2013,代码行数:26,代码来源:BaseTest.cs


示例20: Login

 public void Login()
 {
     driver = new InternetExplorerDriver();
     try
     {
         //Run before any test
         driver.Navigate().GoToUrl(url + "MDM");
         driver.FindElement(By.Id("userNameTextBox")).SendKeys(user);
         driver.FindElement(By.Id("passwordTextBox")).SendKeys(password);
         driver.FindElement(By.Id("loginBtn")).Click();
         Common.WaitForElement(driver, By.ClassName("breadcrumbs"), 30);
     }
     catch (TimeoutException e)
     {
         System.Console.WriteLine("TimeoutException: " + e.Message);
         Assert.Fail(e.Message);
     }
     catch (NoSuchElementException e)
     {
         Assert.Fail(e.Message);
     }
     catch (Exception e)
     {
         System.Console.WriteLine("unhandled exception: " + e.Message);
         Assert.Fail(e.Message);
     }
 }
开发者ID:sharathannaiah,项目名称:CMP,代码行数:27,代码来源:Setup.cs



注:本文中的IWebDriver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IWebElement类代码示例发布时间:2022-05-24
下一篇:
C# IWebContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap