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


C# FirefoxDriver.FindElementById方法代码示例

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


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

示例1: XSSAttack

        public void XSSAttack()
        {
            FirefoxDriver ffox = new FirefoxDriver();

            ffox.Navigate().GoToUrl("localhost:58374/safeinsert.aspx");
            ffox.FindElementById("sname").SendKeys("23',3);<script>document.body.setAttribute('style','background-image: url(\"http://vignette1.wikia.nocookie.net/simpsons/images/7/7b/Eat_My_Shorts.jpg/revision/latest?cb=20100606181712\");');</script>--");
            ffox.FindElementById("sgpa").SendKeys("2.0");
            ffox.FindElementById("InsertStudent").Click();

            ffox.Navigate().GoToUrl("localhost:58374/unsafeshowall.aspx");
            Assert.IsTrue(ffox.FindElementByTagName("body").GetAttribute("style").Contains("url(\"http://vignette1.wikia.nocookie.net/simpsons/images/7/7b/Eat_My_Shorts.jpg/revision/latest?cb=20100606181712"),"XSS Script failed to change background image");

            ffox.Navigate().GoToUrl("localhost:58374/safeshowall.aspx");
            Assert.IsFalse(ffox.FindElementByTagName("body").GetAttribute("style").Contains("url(\"http://vignette1.wikia.nocookie.net/simpsons/images/7/7b/Eat_My_Shorts.jpg/revision/latest?cb=20100606181712"),"SafeShowAll page failed in preventing background image from being injected");
        }
开发者ID:abham07,项目名称:DB-Program-04,代码行数:15,代码来源:testing.cs

示例2: Test3

 public void Test3()
 {
     var driver = new FirefoxDriver();
     driver.Navigate().GoToUrl("http://www.baidu.com");
     //driver.FindElement(By.LinkText("登录")).Click();
     driver.FindElementById("lb").Click();
 }
开发者ID:null2014,项目名称:SeleniumTest,代码行数:7,代码来源:UnitTest1.cs

示例3: logIn

        //log in
        public static void logIn(FirefoxDriver driver)
        {
            if (checkForLogin (driver))
                logOut(driver);

            Console.WriteLine ("Please enter your email address");
            FirefoxWebElement email = driver.FindElementById ("email");
            email.Click ();
            email.SendKeys (Console.ReadLine ());

            Console.WriteLine ("Please enter your password");
            FirefoxWebElement password = driver.FindElementById ("pass");
            password.Click ();
            password.SendKeys (Console.ReadLine ());

            password.SendKeys(Keys.Enter);
        }
开发者ID:dturchenko91,项目名称:SeleniumFacebookTestPageObjects,代码行数:18,代码来源:FacebookPageObject.cs

示例4: Test1

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

示例5: 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

示例6: SearchTest

        public void SearchTest()
        {
            //Navigate to google
            var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://google.com");

            //type text
            var searchbox = driver.FindElementById("gbqfq");
            searchbox.SendKeys("selenium");
            //click search
            var searchBtn = driver.FindElementById("gbqfb");
            searchBtn.Click();

            //check results
            try
            {
                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                wait.Until(ExpectedConditions.ElementExists(By.Id("rso"))); //rso is list of results id
                var list = driver.FindElementById("rso");

                //find selenium website
                var results = list.FindElements(By.ClassName("vurls"));
                foreach (var result in results)
                {
                    if (result.Text == "www.seleniumhq.org/")
                    {
                        //website found
                        Assert.IsTrue(true);
                        driver.Quit();
                        return;
                    }
                }
                //website not found
                Assert.IsTrue(false);
            }
            catch (WebDriverTimeoutException e)
            {
                Assert.Fail("No results found");
            }
            //I am lazy to close windows :)
            driver.Quit();
        }
开发者ID:ferrodox,项目名称:knowledges-sharing,代码行数:42,代码来源:GoogleTest.cs

示例7: ThenIFindThoseItemsOnTheStartPage

 public void ThenIFindThoseItemsOnTheStartPage(int numberOfItems)
 {
     var storePage = "http://localhost:8717/";
     using (var driver = new FirefoxDriver())
     {
         driver.Navigate().GoToUrl(storePage);
         var itemsOnPage = driver.FindElementById("itemCount").Text;
         Assert.AreEqual(numberOfItems.ToString(), itemsOnPage);
         driver.Quit();
     }
 }
开发者ID:jgraber,项目名称:SpecFlowExercise,代码行数:11,代码来源:ProductCatalogSteps.cs

示例8: injectionAttack

        public void injectionAttack()
        {
            FirefoxDriver ffox = new FirefoxDriver();

            ffox.Navigate().GoToUrl("localhost:58374/safeinsert.aspx");
            ffox.FindElementById("sname").SendKeys("Bart Simpson',4);delete from students where name='Bart Simpson';update students set gpa = 4;--");
            ffox.FindElementById("sgpa").SendKeys("2.0");
            ffox.FindElementById("InsertStudent").Click();

            DataTable results = ServerConn.MyQuery("SELECT * FROM students");

            bool InjectionFailed = false;

            foreach (DataRow d in results.Rows)
            {
                if (d.ItemArray[1].Equals("Bart Simpson',4);delete from students where name='Bart Simpson';update students set gpa = 4;--"))
                    InjectionFailed = true;
            }

            Assert.IsTrue(InjectionFailed, "Error: Safe insert did not prevent the SQL injection");

            ffox.Navigate().GoToUrl("localhost:58374/unsafeinsert.aspx");
            ffox.FindElementById("sname").SendKeys("Bart Simpson',4);delete from students where name='Bart Simpson';update students set gpa = 4;--");
            ffox.FindElementById("sgpa").SendKeys("4.0");
            ffox.FindElementById("InsertStudent").Click();

            results = ServerConn.MyQuery("SELECT * FROM students");
            foreach (DataRow d in results.Rows)
            {
                Assert.AreEqual((float) 4, (float) d.ItemArray[2], "Error: Student {0} does not have a GPA of 4", d.ItemArray[1].ToString());
                Assert.AreNotEqual("Bart Simpson", d.ItemArray[1].ToString(), "Error you didn't cover your tracks!");
            }
        }
开发者ID:abham07,项目名称:DB-Program-04,代码行数:33,代码来源:testing.cs

示例9: LoadPage

        public void LoadPage()
        {
            var driver = new FirefoxDriver();
            driver.Url = "http://www.reallysimpleabtesting.co.uk//";

            var element = driver.FindElementByClassName("test");

            var message = element.Text;

            Console.WriteLine(message);

            if (message.Contains("call to action"))
            {
                if (Chance.FlipACoin())
                {
                    var link = driver.FindElementById("calltoaction");
                    link.Click();
                }
            }

            driver.Close();
        }
开发者ID:darkin100,项目名称:ReallySimpleABTesting,代码行数:22,代码来源:SeleniumRun.cs

示例10: SubmitTestPayment

 private void SubmitTestPayment(FirefoxDriver seleniumInstance,Order originalOrder, string paymentUrl)
 {
     seleniumInstance.Url = paymentUrl;
     seleniumInstance.FindElementById("Email").SendKeys("[email protected]");
     AssertOrderAddress(seleniumInstance, originalOrder);
     var continueButton = seleniumInstance.FindElementById("btnAddressEntered") as IWebElement;
     continueButton.ClickWithJavascript(seleniumInstance);
 }
开发者ID:tomgallard,项目名称:pwinty-dotnet,代码行数:8,代码来源:PaymentTest.cs

示例11: DoesPageExist

 public static bool DoesPageExist(FirefoxDriver driver, string pageName)
 {
     GotoPage(driver, pageName);
     bool exists = false;
     try
     {
         IWebElement pageTitle = null;
         PerformActionWithRetry(() => { pageTitle = driver.FindElementById("title-text"); });
         // Space Tools is the page to recover a deleted page.
         exists = pageTitle.Text != "Page Not Found" && pageTitle.Text != "Space Tools";
         if (exists)
         {
             // in case the page is in another space.
             // confluence shows the title with the correct page name
             // but the page does not exist.
             exists = driver.FindElementByCssSelector("div#content div.aui-message p.title").Text != "Page Not Found";
         }
     }
     catch
     {
         // ignored
     }
     return exists;
 }
开发者ID:EbenZhang,项目名称:ConfluenceImporter,代码行数:24,代码来源:MainWindow.xaml.cs

示例12: initializeWebDriver

 public void initializeWebDriver()
 {
     var path = @"C:\Users\Witold\AppData\Roaming\Mozilla\Firefox\Profiles\243mda9k.Selenium";
     var ffProfile = new FirefoxProfile(path, false);
     driver = new FirefoxDriver(ffProfile);
     driver.Navigate().GoToUrl("https://steamcommunity.com/login/home/?goto=0");
     Thread.Sleep(1000);
     var userNameField = driver.FindElementById("steamAccountName");
     var userPasswordField = driver.FindElementById("steamPassword");
     var loginButton = driver.FindElementById("SteamLogin");
     userNameField.SendKeys(SteamCredentials.login);
     userPasswordField.SendKeys(SteamCredentials.password);
     loginButton.Click();
     Thread.Sleep(1000);
 }
开发者ID:Vitekant,项目名称:CSGO-Trader,代码行数:15,代码来源:SeleniumEngine.cs

示例13: 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

示例14: Main


//.........这里部分代码省略.........

                        // Adding Review Object to Database
                        review.timestamp = DateTime.Now;

                        // Building Query to check for duplicated review
                        var duplicatedReviewQuery = Query.EQ ("permalink", review.permalink);

                        // Checking for duplicated review before inserting it
                        if (mongoDB.FindMatch<AppReview> (duplicatedReviewQuery, 1, 0, Consts.REVIEWS_COLLECTION).Count () == 0)
                        {
                            // Inserting Review into MongoDB
                            mongoDB.Insert<AppReview> (review, Consts.REVIEWS_COLLECTION);
                        }
                        else
                        {
                            Console.WriteLine ("Duplicated Review. Skipping App");

                            // When this happens, there are no more reviews to be parsed
                            shouldContinueParsing = false; // Skipping this apps processing
                        }
                    }

                    // Hiccup to avoid Blocking problems
                    Console.WriteLine ("Parsed Reviews: " + _appStatus[appUrl].reviews);
                    Thread.Sleep (new Random ().Next (14000, 21000));

                    if (!shouldContinueParsing)
                    {
                        break;
                    }
                }
            }

            PeopleData:

            Console.WriteLine ("\n\n => Processing People Data");

            Console.WriteLine ("\nSimulating Google Login Using Selenium.");
            using (var firefoxDriver = new FirefoxDriver ())
            {
                // Navigating to Dummy Url - One that I Know that well be asked for a login
                firefoxDriver.Navigate ().GoToUrl ("https://play.google.com/store/people/details?id=101242565951396343093");

                // Reaching Login Fields
                var loginField    = firefoxDriver.FindElementById ("Email");
                var passwordField = firefoxDriver.FindElementById ("Passwd");
                var btnSignIn     = firefoxDriver.FindElementById ("signIn");

                // Sending Credentials to the browser
                loginField.SendKeys ("YOUREMAIL");
                passwordField.SendKeys ("YOURPASSWORD");
                btnSignIn.Click ();

                string lastPeople = "https://play.google.com/store/people/details?id=115037241907660526856";
                bool shouldcontinue = false;

                // Processing Reviewers Data
                foreach (string peopleUrl in mongoDB.FindPeopleUrls ())
                {
                    // Skipping until last link
                    if (peopleUrl == lastPeople)
                    {
                        shouldcontinue = true;
                    }

                    if (!shouldcontinue) continue;

                    // Navigating To the Reviewer Page
                    firefoxDriver.Navigate ().GoToUrl (peopleUrl);

                    // Executing Get Request for the Reviewer page on Google Play
                    string reviewerPage = firefoxDriver.PageSource;

                    // Extracting Reviewer Data from the Page
                    ReviewerPageData reviewerData = dataParser.ParsePeopleData (reviewerPage);

                    // Adding Url to the model
                    reviewerData.reviewerUrl = peopleUrl;

                    // Inserting it to the database - If no previous record of this Reviewer is found
                    if (!mongoDB.IsReviewerOnDatabase (peopleUrl))
                    {
                        mongoDB.Insert<ReviewerPageData> (reviewerData, "ReviewersData");
                    }
                }
            }

            // End of Processing + Console Feedback
            Console.WriteLine ("\n\n == Processing Summary ==");

            foreach (var status in _appStatus.Select (t => t.Value))
            {
                // Message
                string cMessage = "=> App : {0} - Status {1} - Reviews : {2}";

                Console.WriteLine (String.Format (cMessage, status.appName, status.status, status.reviews));
            }

            Console.ReadLine ();
        }
开发者ID:W1N3,项目名称:GooglePlayAppsCrawler,代码行数:101,代码来源:AppDataWorker.cs

示例15: AddAddressAndSubmitTestPayment

 private void AddAddressAndSubmitTestPayment(FirefoxDriver seleniumInstance,Order originalOrder, string paymentUrl,string name,string address1,string townOrCity,string county)
 {
     seleniumInstance.Url = paymentUrl;
     seleniumInstance.FindElementById("Email").SendKeys("[email protected]");
     AssertOrderAddress(seleniumInstance, originalOrder);
     seleniumInstance.FindElementById("Name").SendKeys(name);
     seleniumInstance.FindElementById("Address1").SendKeys(address1);
     seleniumInstance.FindElementById("AddressTownOrCity").SendKeys(townOrCity);
     seleniumInstance.FindElementById("StateOrCounty").SendKeys(county);
     var continueButton = seleniumInstance.FindElementById("btnAddressEntered") as IWebElement;
     continueButton.ClickWithJavascript(seleniumInstance);
 }
开发者ID:tomgallard,项目名称:pwinty-dotnet,代码行数:12,代码来源:PaymentTest.cs


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