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


C# FirefoxDriver.FindElement方法代码示例

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


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

示例1: LoginToSBM

        public static bool LoginToSBM(string siteToTest, string sbmUserName, string sbmUserPass)
        {
            ///We will open that URL and will be performing test over it
            ///string siteToTest = "http://stl-alms-tst4/workcenter/tmtrack.dll?shell=swc";

            ///SBM credentials
           /// string sbmUserName = "admin";
           /// string sbmUserPass = "";

            /// Open the site and wait 5 second while the site is loaded
            IWebDriver drv = new FirefoxDriver();
            ///drv.Navigate().GoToUrl("http://stl-qa-oalmt1/workcenter/tmtrack.dll?shell=swc");
            drv.Navigate().GoToUrl(siteToTest);
            System.Threading.Thread.Sleep(5000);


            ///find login form Username field and send sbmUserName variable content (string)
            IWebElement sbmLoginUName = drv.FindElement(By.Id("authUID"));
            sbmLoginUName.Clear();
            sbmLoginUName.SendKeys(sbmUserName);

            IWebElement sbmLoginUPass = drv.FindElement(By.Id("authPWD"));
            sbmLoginUPass.Clear();
            sbmLoginUPass.SendKeys(sbmUserPass);

            IWebElement sbmLoginBtn = drv.FindElement(By.Id("logonButton"));
            sbmLoginBtn.Click();

            IWebElement foh = drv.FindElement(By.CssSelector("div.cd-more-info:nth-child(1) > p:nth-child(2) > a:nth-child(3)"));
            Assert.AreEqual("Full online help",foh,true);

            return true;
        }
开发者ID:KolomakinA,项目名称:ConsoleApplication3,代码行数:33,代码来源:Program.cs

示例2: RunSalesExecutive

        // GET: RunSystemAdministrator
        public ActionResult RunSalesExecutive()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://localhost:4601/");
            var emp = _employeeService
                             .Queryable()
                             .Where(x => x.DepartmentRoleId == 10)
                             .FirstOrDefault ();
            emp.EmployeeLogin = _employeeLoginService
                                .Queryable()
                                .Where(x => x.EmployeeId == emp.EmployeeId)
                                .FirstOrDefault();
            IWebElement UserName = driver.FindElement(By.Name("UserName"));
            IWebElement Password = driver.FindElement(By.Name("Password"));
            var loginButton = driver.FindElement(By.XPath("/html/body/div/div/div/section/form/button"));

            UserName.SendKeys(emp.EmployeeLogin.UserName);
            Password.SendKeys(emp.EmployeeLogin.Password);
            loginButton.Click();

            Timer timer = new Timer(1000);
            timer.Start();

            timer.Stop();
            return View();
        }
开发者ID:NhlaksMaestro,项目名称:RoleBasedRateSystemSolution,代码行数:27,代码来源:AutomationController.cs

示例3: Main

        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl(@"http://www.weibo.com");

            WebDriverWait waitPageOpen = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
            IWebElement inpt_username = waitPageOpen.Until<IWebElement>((d) => { return d.FindElement(By.Name("username")); });
            waitPageOpen.Until((d) => { return inpt_username.Displayed; });
            inpt_username.SendKeys(@"[email protected]");

            IWebElement inpt_pwd = driver.FindElement(By.Name("password"));
            inpt_pwd.SendKeys(@"kodakpdc2000");

            IWebElement btn_login = driver.FindElement(By.ClassName("W_btn_g"));
            btn_login.Click();

            waitPageOpen.Until((d)=>{return d.Title.StartsWith("我的首页");});

            //IList<IWebElement> personInfos = driver.FindElements(By.ClassName("user_atten"));
            //if (personInfos.Count == 1)
            //{ personInfos[0].FindElement(By.PartialLinkText("粉丝")).Click(); }

            IWebElement temp = driver.FindElement(By.PartialLinkText("粉丝"));
            temp.Click();

            Console.Read();
        }
开发者ID:AnnikaXiao,项目名称:SeleniumWeibo2,代码行数:28,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();

            int idInicio = 30000;
            int idFinal = 22000;
            int contador = 1;
            String url = "";

            driver.Navigate().GoToUrl(url + idInicio);
            driver.Manage().Window.Maximize();
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"e:\AllStudents.csv", true))
            {

                while (idInicio > idFinal)
                {
                    driver.Navigate().GoToUrl(url + idInicio);
                    IWebElement nome = driver.FindElement(By.Id("txtNome"));
                    IWebElement email = driver.FindElement(By.Id("txtmail_maior"));
                    if (email.GetAttribute("value").ToString() != "")
                    {
                        Console.WriteLine(contador + " - " + idInicio.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString());
                        file.WriteLine(contador + ";" + idInicio.ToString() + ";" + email.GetAttribute("value").ToString() +";"+ nome.GetAttribute("value").ToString());

                        contador++;
                    }
                    idInicio--;
                }
            }
        }
开发者ID:wesleyxavierTestes,项目名称:BuscaDados,代码行数:30,代码来源:Program.cs

示例5: Attack1_Protected

        public void Attack1_Protected()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInput.aspx");

            IWebElement query = driver.FindElement(By.Name("fullName"));

            query.SendKeys("a','2.1'); update students * set gpa = 4.0; --");
            query = driver.FindElement(By.Name("GPA"));
            query.SendKeys("3");
            query = driver.FindElement(By.Name("button"));
            query.Click();
            System.Threading.Thread.Sleep(5000);

            List<LU.ENGI3675.Proj04.App_Code.Students> students =
                LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read();
            bool allfour = true;
            foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students)
            {
                if (temp.GPA < 4.0) allfour = false;
                Debug.Write((string)temp.Name);
                Debug.Write(" ");
                Debug.WriteLine((double)temp.GPA);
            }
            Assert.IsFalse(allfour);    //if they aren't all 4.0 gpa, then protected against SQL injection
            driver.Quit();
        }
开发者ID:shojimonk,项目名称:Databases-Project-4,代码行数:27,代码来源:UnitTest1.cs

示例6: WindowProcess_Demo2

        public void WindowProcess_Demo2()
        {
            var articleName = "[小北De编程手记] : Lesson 02 - Selenium For C# 之 核心对象";

            _output.WriteLine("Step 01 : 启动浏览器并打开Lesson 01 - Selenium For C#");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com/NorthAlan/p/5155915.html";

            _output.WriteLine("Step 02 : 点击链接打开新页面。");
            var lnkArticle02 = driver.FindElement(By.LinkText(articleName));
            lnkArticle02.Click();

            _output.WriteLine("Step 03 : 根据标题获取新页面的句柄。");
            var oldWinHandle = driver.CurrentWindowHandle;
            foreach (var winHandle in driver.WindowHandles)
            {
                driver.SwitchTo().Window(winHandle);
                if (driver.Title.Contains(articleName))
                {
                   break;
                }
            }

            _output.WriteLine("Step 04 : 验证新页面标题是否正确。");
            var articleTitle = driver.FindElement(By.Id("cb_post_title_url"));
            Assert.Equal<string>(articleName, articleTitle.Text);

            _output.WriteLine("Step 05 : 关闭浏览器。");
            driver.Quit();

        }
开发者ID:DemoCnblogs,项目名称:Selenium,代码行数:31,代码来源:Lesson07_WindowProcess.cs

示例7: Attack2_NonProtected

        public void Attack2_NonProtected()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInputUNSAFE.aspx");

            IWebElement query = driver.FindElement(By.Name("fullNameUS"));

            query.SendKeys("a','2.1'); update students * set gpa = 4.0; --");
            query = driver.FindElement(By.Name("GPAUS"));
            query.SendKeys("0");
            query = driver.FindElement(By.Name("button"));
            query.Click();
            System.Threading.Thread.Sleep(1000);

            List<LU.ENGI3675.Proj04.App_Code.Students> students =
                LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read();

            foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students)
            {
                Assert.IsTrue((double)temp.GPA == 4);   //if any of them aren't 4.0, injection failed
                Debug.Write((string)temp.Name);
                Debug.Write(" ");
                Debug.WriteLine((double)temp.GPA);
            }
            driver.Quit();
        }
开发者ID:shojimonk,项目名称:Databases-Project-4,代码行数:26,代码来源:UnitTest1.cs

示例8: Main

        static void Main(string[] args)
        {
            // Compile project
            // Copy "index.html" and "lenna.png" into CSFileUpload.exe directory (bin\Debug\)
            // Run and enjoy!

            // создаём объект WebDriver для браузера FireFox
            var driver = new FirefoxDriver();

            // открываем страницу с формой загрузки файла
            var fileUri = GetUriFromPath(Path.Combine(Environment.CurrentDirectory, "index.html"));
            driver.Url = fileUri;

            // находим элемент <input type="file">
            var txtFileUpload = driver.FindElement(By.Id("file"));

            // заполняем элемент путём до загружаемого файла
            var sourceFile = Path.Combine(Environment.CurrentDirectory, "lenna.png");
            txtFileUpload.SendKeys(sourceFile);

            // находим элемент <input type="submit">
            var btnSubmit = driver.FindElement(By.Id("submit"));

            // нажимаем на элемент (отправляем форму)
            btnSubmit.Click();

            // закрываем браузер
            driver.Quit();
        }
开发者ID:Khrol,项目名称:at.info-knowledge-base,代码行数:29,代码来源:upload_file.cs

示例9: Main

        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            const int idInicio = 0;
            const int idFim = 1000;

            int id = idInicio;
            String url = "http://fcv.matheusacademico.com.br/Aluno/frmAlunoAlteracao.asp?id=";

            driver.Navigate().GoToUrl(url + id);
            driver.Manage().Window.Maximize();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\AllStudents1.txt", true))
            {
                while (id < idFim)
                {
                    driver.Navigate().GoToUrl(url + id);
                    IWebElement nome = driver.FindElement(By.Id("txtNome"));
                    IWebElement email = driver.FindElement(By.Id("txtmail_maior"));

                    if (nome.GetAttribute("value").ToString() != "")
                        file.WriteLine(id.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString());
                    id++;
                }
            }
        }
开发者ID:wesleyxavierTestes,项目名称:PesquisadorAlunos,代码行数:26,代码来源:Program.cs

示例10: TestMensagemAlertaNenhumSelecionado

        public void TestMensagemAlertaNenhumSelecionado()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl(SITE_URL);
            driver.FindElement(By.Id("btnSolucionar")).Click();

            Assert.IsTrue(driver.FindElement(By.Id("divErrorMessage")).Displayed);
            driver.Quit();
        }
开发者ID:rovianvz,项目名称:Detetive,代码行数:9,代码来源:InterfaceTests.cs

示例11: CreateBugTest

        public void CreateBugTest()
        {
            IWebDriver driver = new FirefoxDriver();
            string baseURL = "http://ifdefined.com/btnet/bugs.aspx";
            StringBuilder verificationErrors = new StringBuilder();

            driver.Navigate().GoToUrl(baseURL);
            try
            {
                Assert.AreEqual("BugTracker.NET - bugs", driver.Title);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }
            driver.FindElement(By.XPath("//div[contains(@class, 'align')]/table/tbody/tr/td/a")).Click();
            try
            {
                Assert.AreEqual("BugTracker.NET - Create Bug", driver.Title);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }

            try
            {
                Assert.AreEqual("Project:", driver.FindElement(By.XPath("//span[conatins(@id, 'project_label')]")).Text);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }
            // ERROR: Caught exception [ReferenceError: selectLocator is not defined]
            driver.FindElement(By.CssSelector("option[value=\"3\"]")).Click();

            try
            {
                Assert.AreEqual("[no project] DemoProject HasCustomFieldsProject HasDifferentPermissionsProject", driver.FindElement(By.Id("project")).Text);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }

            try
            {
                Assert.AreEqual("Project-specific", driver.FindElement(By.Id("label_pcd1")).Text);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }

            driver.Quit();
        }
开发者ID:ekostadinov,项目名称:MyProjects,代码行数:56,代码来源:TestBugtracker.cs

示例12: MagentoIncorrectUser

        public void MagentoIncorrectUser()
        {
            IWebDriver driver = new FirefoxDriver();
            string baseURL = "http://demo.nostresscommerce.cz/";
            StringBuilder verificationErrors = new StringBuilder();

            driver.Navigate().GoToUrl(baseURL);

            driver.FindElement(By.XPath("//*[contains(@class, 'links')]/li/a")).Click();
            driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).Clear();
            driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).SendKeys("[email protected]");
            driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).Clear();
            driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).SendKeys("123456");
            driver.FindElement(By.Id("send2")).Click();
            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if ("Login or Create an Account" == driver.FindElement(By.CssSelector("h1")).Text) break;
                }
                catch (Exception)
                { }
                Thread.Sleep(1000);
            }
            try
            {
                Assert.AreEqual("Login or Create an Account", driver.FindElement(By.CssSelector("h1")).Text);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }
            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if ("Invalid login or password." == driver.FindElement(By.CssSelector("li > span")).Text) break;
                }
                catch (Exception)
                { }
                Thread.Sleep(1000);
            }
            try
            {
                Assert.AreEqual("Invalid login or password.", driver.FindElement(By.CssSelector("li > span")).Text);
            }
            catch (Exception e)
            {
                verificationErrors.Append(e.Message);
            }

            driver.Quit();
        }
开发者ID:ekostadinov,项目名称:MyProjects,代码行数:55,代码来源:TestMagento.cs

示例13: Add_Tweet_FindNewTweetInNewsfeed

        public void Add_Tweet_FindNewTweetInNewsfeed()
        {
            firefox = new FirefoxDriver();
            firefox.Navigate().GoToUrl("http://localhost:57336/");
            //firefox.FindElement(By.Id("register")).Click();
            firefox.FindElement(By.Id("login")).Click();

            //register page
            //firefox.FindElement(By.Id("inputFirstName")).SendKeys("testFirstName");
            //firefox.FindElement(By.Id("inputLastName")).SendKeys("testLastName");
            //firefox.FindElement(By.Id("inputEmail")).SendKeys("[email protected]");
            //firefox.FindElement(By.Id("inputPassword")).SendKeys("123");
            //firefox.FindElement(By.Id("submit")).Click();
            //firefox.FindElement(By.Id("login")).Click();

            //log in page
            firefox.FindElement(By.Id("inputEmail")).SendKeys("[email protected]");
            firefox.FindElement(By.Id("inputPassword")).SendKeys("123");
            firefox.FindElement(By.Id("login")).Click();

            firefox.FindElement(By.Name("Body")).Click();
            firefox.FindElement(By.Name("Body")).SendKeys("test Tweet");

            firefox.FindElement(By.Id("tweetbutton")).Click();
            firefox.FindElement(By.Id("home")).Click();

            string tweetMessage = firefox.FindElement(By.TagName("h5")).Text;

            Assert.IsTrue(tweetMessage == "test Tweet");
        }
开发者ID:vlad94md,项目名称:team04,代码行数:30,代码来源:TweetControllerTests.cs

示例14: Should_display_asterisk_against_missing_user_name

        public void Should_display_asterisk_against_missing_user_name()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://localhost:1392/");
            driver.FindElement(By.Id("login_LoginButton")).Click();

            var missing = driver.FindElement(By.Id("login_UserNameRequired"));
            Assert.IsTrue(missing.Displayed);

            driver.Quit();
        }
开发者ID:NathanGloyn,项目名称:Selenium-UI-Testing,代码行数:11,代码来源:When_trying_to_access_the_site.cs

示例15: HackathonTest

        public void HackathonTest()
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://testerzy.pl");

            driver.FindElement(By.Id("mod-search-searchword")).SendKeys("hackathon dev qa");
            driver.FindElement(By.ClassName("button")).Click();

            Assert.True(driver.FindElement(By.ClassName("result-title")).Text.Contains("Hackathon"));
            driver.Quit();
        }
开发者ID:ibezuglyi,项目名称:Hackathon,代码行数:12,代码来源:Class1.cs


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