当前位置: 首页>>代码示例>>C#>>正文


C# FirefoxDriver.FindElementByXPath方法代码示例

本文整理汇总了C#中OpenQA.Selenium.Firefox.FirefoxDriver.FindElementByXPath方法的典型用法代码示例。如果您正苦于以下问题:C# FirefoxDriver.FindElementByXPath方法的具体用法?C# FirefoxDriver.FindElementByXPath怎么用?C# FirefoxDriver.FindElementByXPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenQA.Selenium.Firefox.FirefoxDriver的用法示例。


在下文中一共展示了FirefoxDriver.FindElementByXPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            FirefoxDriver driver = new FirefoxDriver();
            //напрямую в гугл не пробиться - осядем на вводе капчи изза подозрительной деятельности
            //потому пойдем через яндекс
            driver.Url = "https://ya.ru";
            
            //ищем гугл
            driver.FindElementByXPath("//*[@id='text']").SendKeys("Google" + Keys.Enter);

            //теперь переходим по ссылке от яндекса
            driver.Url = driver.FindElementByPartialLinkText("google.ru").Text.ToString();

            driver.Url = "https://www.google.ru/#newwindow=1&q=zerg+rush";

            do
            {

                try
                {
                    driver.FindElementByXPath(".//*[@class='zr_zergling_container']").Click();
                }
                catch
                {
                    //если зерглинга еще нет
                }
            } while (true); //TODO: заменить на число из статистики

            Console.ReadKey();
            driver.Quit();
        }
开发者ID:raptorbox01,项目名称:csharp_exercises,代码行数:31,代码来源:Program.cs

示例2: testHomePage

        /// <summary>
        /// Test all links on the Krossover home page
        /// </summary>
        public void testHomePage(FirefoxDriver driver)
        {
            string homePage = "http://www.krossover.com/";
            driver.Navigate().GoToUrl(homePage);
            Thread.Sleep(1000);

            //find all links on the page
            IList<IWebElement> links = driver.FindElementsByTagName("a");

            //loop through all of the links on the page
            foreach (IWebElement link in links)
            {
                try
                {
                    //check if any of the links return a 404
                    link.SendKeys(Keys.Control + Keys.Enter);
                    driver.SwitchTo().Window(driver.WindowHandles.Last());

                    driver.FindElementByXPath("//div[contains(@class, '404')]");
                    log(link.GetAttribute("href") + " is broken.  Returned 404");

                    driver.SwitchTo().Window(driver.WindowHandles.First());
                }
                catch
                {
                    //continue to the next link
                    continue;
                }

            }
            driver.Quit(); //kill the driver
        }
开发者ID:dhruv0018,项目名称:Krossover,代码行数:35,代码来源:TestHomePage.cs

示例3: logOut

 //log out
 public static void logOut(FirefoxDriver driver)
 {
     if (checkForLogin (driver)) {
         driver.FindElementById ("userNavigationLabel").Click();
         driver.FindElementByXPath ("/html/body/div[2]/div/div/div/div/div[1]/div/div/ul/li[12]/a/span/span").Click ();
         return;
     }
     return false;
 }
开发者ID:dturchenko91,项目名称:SeleniumFacebookTestPageObjects,代码行数:10,代码来源:FacebookPageObject.cs

示例4: Test2

 public void Test2()
 {
     var driver = new FirefoxDriver();
     driver.Navigate().GoToUrl("http://www.qtptutorial.net/automation-practice");
     driver.Manage().Window.Maximize();
     driver.FindElementByClassName("buttonClassExample").Click();
     var elementCheck = driver.FindElementByXPath("//p[contains(text(),'Button success')]").Displayed;
     Assert.IsFalse(elementCheck, "Element was not present");
 }
开发者ID:nadvolod,项目名称:ParallelTestingTutorial,代码行数:9,代码来源:ParallelLocal.cs

示例5: Main

        static void Main(string[] args)
        {
            FirefoxDriver driver = new FirefoxDriver(); //создаем драйвер файрфокса

            driver.Url = "http://10fastfingers.com/typing-test/russian"; //идем на сайт с клавиатурным вводом

            IWebElement InTextbox = driver.FindElementByXPath(".//*[@id='inputfield']"); // создаем экз интерфейса Iwebelement привязываем его к окошку ввода 

            string sInString = ""; //переменная для хранения слова для ввода (чтобы не создавать и разрушать её в цикле, нагружая бедный GC)

            for (int i = 0; i < 180; i++) // С-way хочешь 50 слов в минуту - пиши 50, 100 - 100 (всего похоже 185-190 слов)
            {
                sInString = driver.FindElementByXPath(".//*[@id='row1']/span[@class = 'highlight']").Text.ToString(); //пихаем в строку текст подсвеченного слова
                InTextbox.SendKeys(sInString); //посылаем его на ввод (выглядит как вставка из буфера)
                InTextbox.SendKeys(Keys.Space); // пробел для перехода на новое слово
            }

            Console.ReadKey(); // держим окно при дебаге

            driver.Quit(); //закрываем драйвер
        }
开发者ID:raptorbox01,项目名称:csharp_exercises,代码行数:21,代码来源:Program.cs

示例6: FindingStuff_CarBuzz

        public void FindingStuff_CarBuzz()
        {
            var browser = new FirefoxDriver();
            browser.Navigate().GoToUrl("http://carbuzz.heroku.com/car_search");

            browser.FindElementByName("make_17").Click();
            browser.FindElementByName("make_14").Click();
            browser.FindElementByName("make_11").Click();

            Assert.That(browser.PageSource.Contains(" 5 car reviews found"));

            browser.FindElementByXPath("//ul[@class='seats']/li/button[@value='4']").Click();

            Assert.That(browser.PageSource.Contains(" 1 car reviews found"));
        }
开发者ID:AndrewVos,项目名称:Coypu,代码行数:15,代码来源:RawWebdriver.cs

示例7: Main

        static void Main(string[] args)
        {
            RemoteWebDriver browser = new FirefoxDriver();

            try
            {
                browser.Navigate().GoToUrl("http://alitrack.ru/");

                #region Login
                if (browser.FindElementByName("login") != null)
                {
                    browser.FindElementByName("login").SendKeys(cabinet.alitrack.ru.Properties.Settings.Default.UserName);
                    browser.FindElementByName("pass").SendKeys(cabinet.alitrack.ru.Properties.Settings.Default.Password);
                    browser.FindElementByXPath("//input[@type='submit']").Click();
                }
                #endregion

                WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");
                browser.Navigate().GoToUrl("http://cabinet.alitrack.ru/tracking/");
                WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");


                if (browser.PageSource.Contains("trackingCheckAllItems"))
                {
                    #region update
                    browser.FindElementById("trackingCheckAllItems").Click();
                    var alert = browser.SwitchTo().Alert();
                    alert.Accept();
                    WaitForCompleteXPath(browser, "//div[@id='processingWindow' and contains(@style,'display: none;')]");
                    var trackingRows = browser.FindElementsByClassName("tracking-row");

                    foreach (var trackingRow in trackingRows)
                    {
                        Console.WriteLine(trackingRow.FindElement(By.ClassName("name")).Text);
                        string number = trackingRow.GetAttribute("id").Replace("trow", string.Empty);
                        if (browser.PageSource.Contains(string.Format("id=\"refresh-button{0}\"", number)))
                        {
                            browser.FindElementById("refresh-button" + number).Click();
                            WaitForCompleteXPath(browser, "//div[@id='processingWindow' and contains(@style,'display: none;')]");
                        }
                    }
                    #endregion

                    #region find new
                    browser.Navigate().GoToUrl("http://cabinet.alitrack.ru/tracking/");
                    WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");
                    var trackingNewRows = browser.FindElementsByClassName("tracking-row");
                    Regex regexButtons = new Regex("<div[^>]*class=\"buttons\"[^>]*>(.*?)</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    Regex regexFull = new Regex("<div[^>]*class=\"fullinfo\"[^>]*>(.*?)</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    int newCount = 0;
                    StringBuilder newItems = new StringBuilder();
                    foreach (var trackingRow in trackingNewRows)
                    {
                        Console.WriteLine(trackingRow.FindElement(By.ClassName("name")).Text);
                        if (!string.IsNullOrEmpty(trackingRow.FindElement(By.ClassName("newSteps")).Text))
                        {
                            newCount++;
                            newItems.AppendLine(regexFull.Replace(regexButtons.Replace(trackingRow.GetAttribute("outerHTML"), string.Empty), string.Empty));
                        }
                    }
                    #endregion

                    if (newCount > 0)
                    {
                        #region Processing
                        newItems.Replace("class=\"clear\"", "style=\"clear: both;\"");
                        newItems.Replace("class=\"newSteps\"", "style=\"font-size: 11px;font-weight: normal;color: #a00;display: inline-block;padding: 0 0 0 4px;margin: -5px 0 0 0;vertical-align: top;\"");
                        newItems.Replace("class=\"info\"", "style=\"padding: 0;	overflow: hidden;	white-space: nowrap;color: #50749b;\"");
                        newItems.Replace("class=\"meta\"", "style=\"padding: 3px 0 0 0;	display:inline-block;overflow: hidden;color: #97adc3;white-space: nowrap;\"");
                        newItems.Replace("class=\"name\"", "style=\"font-size: 18px; padding: 9px 0 5px 0; overflow: hidden; color: #50749b; cursor: pointer; white-space: nowrap;\"");

                        newItems.Replace("class=\"tracking-row hasmoves\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #d0e7ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasexport\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #bad2ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row haslong\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #c0b4ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hascustom\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #e6ff8c;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasnotrace\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ffc994; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasnative\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #b3fab3;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasarrive\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #161; color: #b3fab3; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row haswarning\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ffd0d0; color: #50749B; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasrecieved\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #DDD;	border-radius: 5px;\"");


                        newItems.Replace("class=\"tracking-row\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ebeff3; border-radius: 5px;\"");

                        newItems.Replace("class=\"main\"", "style=\"padding: 0 0 8px 8px; float: left; background-color: #ebeff3; border-radius: 0 5px 5px 0; cursor: pointer; position: relative;\"");
                        newItems.Replace("class=\"time\"", "style=\"font-size: 10px; line-height: 10px; color: #50749b; text-align: center; padding: 35px 0 0;\"");
                        newItems.Replace("class=\"icon\" style=\"", "style=\"float: left;width: 60px;height: 60px;border-radius: 5px 0 0 5px; overflow: hidden; cursor: default;background: url(trackicons/0.png) 14px 5px no-repeat;");
                        newItems.Replace(" class=\"infopos\"", string.Empty);
                        #endregion

                        #region Send report
                        string report = cabinet.alitrack.ru.Properties.Resources.Template.Replace("{NEW}", newItems.ToString());
                        SmtpClient client = new SmtpClient(cabinet.alitrack.ru.Properties.Settings.Default.SMTP);
                        MailAddress from = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailFrom);
                        MailAddress to = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailTo);
                        MailMessage message = new MailMessage(from, to);
                        message.Subject = string.Format("{0} new update from alitrack", newCount);
                        message.IsBodyHtml = true;
                        message.Body = report;
                        client.Send(message);
//.........这里部分代码省略.........
开发者ID:rechkin,项目名称:cabinet.alitrack.ru,代码行数:101,代码来源:Program.cs


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