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


C# RemoteWebDriver.FindElement方法代码示例

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


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

示例1: Authenticate

		public static IWebDriver Authenticate()
		{
			string email = "[email protected]";
			IWebDriver webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());
			//webDriver.Manage().Window.Maximize();
			webDriver.Navigate().GoToUrl("http://dev.icms/Account/Login");
			//Enter email address on login page
			IWebElement emailLogin = webDriver.FindElement(By.Id("Email"));
			emailLogin.Clear();
			emailLogin.SendKeys(email);
			IWebElement authenticateButton = webDriver.FindElement(By.Id("requestauth"));
			authenticateButton.Click();
			//this should have sent me an email
			//Let's pretend we got the email and check the server for the authtoken and plug it into the URL

			string token = HttpUtility.UrlEncode(TestUtilities.AuthenticationUtil.GetAuthToken(email));
			string goToUrl = string.Format("http://dev.icms/account/authorize/?authtoken={0}&email={1}&returnUrl=%2f", token, email);

			webDriver.Quit();
			webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());

			webDriver.Navigate().GoToUrl(goToUrl);

			//Check DOM to see if we are logged in
			IWebElement elem = webDriver.FindElement(By.CssSelector("h1"));
			//webDriver.Quit();
			if (elem.Text == "Welcome Admin Development")
			{
				return webDriver;
			}
			return null;
		}
开发者ID:MarneeDear,项目名称:Terminal-Management-Apps-Tests,代码行数:32,代码来源:BaseTest.cs

示例2: DeleteItem

        protected void DeleteItem(RemoteWebDriver browser)
        {
            IWebElement link = browser.FindElement(By.Id("blAHrefLink0"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("DesktopDeleteButton"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);
        }
开发者ID:ehelin,项目名称:TgimbaSeleniumTests,代码行数:10,代码来源:BaseDesktopTest.cs

示例3: Search

        protected void Search(RemoteWebDriver browser)
        {
            browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
            System.Threading.Thread.Sleep(_testStepInterval);

            IWebElement link = browser.FindElement(By.Id("searchButtonSubmit"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("CancelSearchResultDisplay"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("searchButtonSubmit"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("ProcessEdit0"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("DesktopDeleteButton"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("searchButtonSubmit"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("ProcessEdit0"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("DesktopEditButton"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            browser.FindElement(By.Id("BIItemName")).SendKeys(" edited item value");
            System.Threading.Thread.Sleep(_testStepInterval);

            IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
            SelectElement selectElement = new SelectElement(rankingItemSelect);
            selectElement.SelectByText("Warm");
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("EditBIButtonSubmit"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);
        }
开发者ID:ehelin,项目名称:TgimbaSeleniumTests,代码行数:55,代码来源:BaseDesktopTest.cs

示例4: setup

        //private static ISelenium selenium;

        
        
        public static void setup()
        {
            
            IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),DesiredCapabilities.HtmlUnit());
                        
            //driver = new FirefoxDriver();
            Selenium.WebDriverBackedSelenium s = new Selenium.WebDriverBackedSelenium(driver, @"http://site4.way2sms.com/content/index.html");
            s.Start();
            driver.Navigate().GoToUrl("http://site4.way2sms.com/content/index.html");
            
            
            WaitForLinkTextPresent(driver, "► click here to go to way2sms.com", 40);
            driver.FindElement(By.Id("username")).SendKeys("9916089888");
            driver.FindElement(By.Id("password")).SendKeys("suprwolf");
            driver.FindElement(By.Id("button")).Click();
            

            if (WaitIdPresent(driver, "quickclose1",40000))
            {
                driver.FindElement(By.Id("quickclose1")).Click();
            }

            driver.FindElement(By.Id("quicksms")).Click();
            driver.SwitchTo().Frame("frame");
            s.WaitForPageToLoad("30000");
            driver.FindElement(By.Id("MobNo")).SendKeys("9916089888");
            WaitIdPresent(driver, "textArea", 400);
            driver.FindElement(By.Id("textArea")).SendKeys("test");

            driver.FindElement(By.Id("Send")).Submit();
            driver.FindElement(By.LinkText("Logout")).Clear();
           
            
        }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:38,代码来源:Class1.cs

示例5: SignInAsAdmin

        /// <summary>
        /// Log a user into the website as an administrator
        /// </summary>
        /// <param name="driver"></param>
        protected void SignInAsAdmin(RemoteWebDriver driver)
        {
            //Notice navigation is slightly different than the Java version
            //This is because 'get' is a keyword in C#
            driver.Navigate().GoToUrl(BaseUrl + "/User/SignIn");

            // Find the text input element by its name
            driver.FindElement(By.Name("Email")).SendKeys(_adminEmail);
            driver.FindElement(By.Name("Password")).SendKeys(_adminPass);
            driver.FindElement(By.CssSelector("button.btn-primary")).Click();
            driver.WaitFor(u => u.Url.Contains("Manage"));
        }
开发者ID:theriddlebrothers,项目名称:Honeypot,代码行数:16,代码来源:BaseTest.cs

示例6: FindPrice

        public void FindPrice()
        {
            IWebDriver driver_ = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver_.Navigate().GoToUrl("http://www.momoshop.com.tw");

            driver_.FindElement(By.CssSelector("#keyword")).SendKeys(this.SearchKeyWord_);
            driver_.FindElement(By.CssSelector(".inputbtn")).Click();

            Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();

            try
            {
                if (driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count == 0)
                {
                    ReadProductDetail(driver_.Url, ref info);
                }
                else
                {
                    var PageCount = driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count;

                    for (var CurrentPage = 1; CurrentPage <= PageCount;)
                    {
                        List<IWebElement> products = driver_.FindElements(By.XPath("//*[@id=\"chessboard\"]/li/a")).ToList();
                        foreach (var product in products)
                        {
                            ReadProductDetail(product.GetAttribute("href"), ref info);
                        }

                        //Last Page
                        if (CurrentPage == PageCount)
                        {
                            break;
                        }

                        //Next Page
                        ++CurrentPage;
                        driver_.FindElement(By.XPath(string.Format("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li[{0}]/a", CurrentPage))).Click();
                    }

                }
            }
            catch (NoSuchElementException)
            {
            }

            this.ProductDetail_.Add("momo", info);
            driver_.Quit();
            if (LocalDriver_ != null)
            {
                LocalDriver_.Quit();
            }
            return;
        }
开发者ID:Shi-Yu-Chen,项目名称:FindPrice,代码行数:53,代码来源:SearchMomo.cs

示例7: EditItem

        protected void EditItem(RemoteWebDriver browser)
        {
            IWebElement link = browser.FindElement(By.Id("btnEdit0"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            browser.FindElement(By.Id("BIItemName")).SendKeys("edited item value");
            System.Threading.Thread.Sleep(_testStepInterval);

            IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
            SelectElement selectElement = new SelectElement(rankingItemSelect);
            selectElement.SelectByText("Warm");
            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("EditBIButtonSubmit"));
            link.Click();
        }
开发者ID:ehelin,项目名称:TgimbaSeleniumTests,代码行数:17,代码来源:BaseMobileTest.cs

示例8: SaveAndRecordSubmittedTags

		public static string[] SaveAndRecordSubmittedTags( RemoteWebDriver driver )
		{
			// Save
			driver.FindElement( By.Id( "save_tags" ) ).Click();

			// Stash the values we entered
			var tagsAsSubmitted = driver.FindElements( By.CssSelector( "input.tag_name" ) ).Select( tagNameEl => tagNameEl.GetAttribute( "value" ).Trim() ).ToArray();

			// Wait for the success report
			new WebDriverWait( driver, TimeSpan.FromSeconds( 10 ) ).Until( d =>
			{
				var messagesElement = driver.FindElement( By.Id( "messages" ) );
				return messagesElement.Displayed && -1 != messagesElement.Text.IndexOf( "saved successfully", StringComparison.InvariantCultureIgnoreCase );
			} );

			return tagsAsSubmitted;
		}
开发者ID:InishTech,项目名称:Sp.Api,代码行数:17,代码来源:AdminTags.cs

示例9: Selenium_Server_Test

        public void Selenium_Server_Test()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver.Url = "http://www.google.com";
            var searchBox = driver.FindElement(By.Id("lst-ib"));
            searchBox.SendKeys("Lotus flower");
            searchBox.SendKeys(Keys.Enter);

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            var imagetext = driver.FindElement(By.LinkText("Kuvahaku"));
            Assert.That(imagetext.Text, Is.EqualTo("Kuvahaku"));
            imagetext.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); //avoid error on no such element
            var imagelistId = driver.FindElement(By.Id("rg_s"));
            var fouthdivclass = imagelistId.FindElements(By.CssSelector("[class='rg_di rg_el ivg-i']"))[1].FindElement(By.TagName("a"));
            fouthdivclass.Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            var ImageLink = driver.FindElement(By.LinkText("Näytä kuva"));
            ImageLink.Click();
        }
开发者ID:Qianfinland,项目名称:Net,代码行数:21,代码来源:Program.cs

示例10: FindPrice

        public void FindPrice()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver.Navigate().GoToUrl("http://www.pcstore.com.tw/");
            Thread.Sleep(1000);

            //#id_search_word
            driver.FindElement(By.CssSelector("#id_search_word")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"top-search\"]/img")).Click();

            Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();

            for (; ; )
            {
                List<IWebElement> ProductList = driver.FindElements(By.XPath("//*[@id=\"keyad-pro-right3\"]/div[1]/a")).ToList();
                foreach (var product in ProductList)
                {
                    ReadProductDetail(product.GetAttribute("href"), ref info);
                }

                try
                {
                    driver.FindElement(By.XPath("//*[@id=\"container\"]/div[10]/table[1]/tbody/tr/td[5]/a")).Click();
                    Thread.Sleep(1000);
                }
                catch (System.Exception)
                {
                    break;
                }
            }

            this.ProductDetail_.Add("PcHome", info);
            if (LocalDriver_ != null)
            {
                LocalDriver_.Quit();
            }
            driver.Quit();
            return;
        }
开发者ID:Shi-Yu-Chen,项目名称:FindPrice,代码行数:39,代码来源:SearchPchome.cs

示例11: GivenThatINavigateToABlogPostThatContainsAnImage

        public void GivenThatINavigateToABlogPostThatContainsAnImage()
        {
            var driver = new RemoteWebDriver(new Uri("http://localhost"), DesiredCapabilities.HtmlUnitWithJavaScript());

            // Find the text input element by its name
            driver.Navigate();

            // Enter something to search for
            IWebElement element = driver.FindElement(By.Id(""));

            // Now submit the form. WebDriver will find the form for us from the element
            //element.S
        }
开发者ID:kevinrjones,项目名称:mblog,代码行数:13,代码来源:MBlogMediaStepDefinitions.cs

示例12: AddItemFromEditMenu

        protected void AddItemFromEditMenu(RemoteWebDriver browser)
        {
            IWebElement link = browser.FindElement(By.Id("blAHrefLink0"));
            link.Click();

            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("DesktopAddButton"));
            link.Click();
            System.Threading.Thread.Sleep(_testStepInterval);

            browser.FindElement(By.Id("BIItemName")).SendKeys("Bucket List Item 2");
            System.Threading.Thread.Sleep(_testStepInterval);

            IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
            SelectElement selectElement = new SelectElement(rankingItemSelect);
            selectElement.SelectByText("Cool");

            System.Threading.Thread.Sleep(_testStepInterval);

            link = browser.FindElement(By.Id("AddBIButtonSubmit"));
            link.Click();
        }
开发者ID:ehelin,项目名称:TgimbaSeleniumTests,代码行数:23,代码来源:BaseDesktopTest.cs

示例13: CreateCustomerShouldSucceed

		public static void CreateCustomerShouldSucceed( RemoteWebDriver driver, AuthenticatingNavigator navigator )
		{
			using ( driver.FinallyQuitGuard() ) // TODO improve this using http://xunit.codeplex.com/workitem/9798 ( WAS: http://xunit.codeplex.com/discussions/362097 )
			{
				navigator.NavigateWithAuthenticate( driver, "Sp.Web.Consume/Customer/Create" );

				WebDriverWait wait = new WebDriverWait( driver, TimeSpan.FromSeconds( 5 ) );
				wait.Until( d => d.FindElement( By.Id( "create-view" ) ) );
				IWebElement nameElement = driver.FindElement( By.Id( "name" ) );
				string anonymousCustomerName = "anonymousName" + Guid.NewGuid();
				nameElement.SendKeys( anonymousCustomerName );

				IWebElement externalIdElement = driver.FindElement( By.Id( "externalId" ) );
				externalIdElement.SendKeys( "anonymousExternalId" );

				IWebElement createButton = driver.FindElement( By.Id( "add-customer" ) );
				createButton.Click();

				wait.Until( d => d
					.FindElement( By.Id( "messages" ) )
					.Text.Contains( "Customer created successfully" ) );
			}
		}
开发者ID:InishTech,项目名称:Sp.Api,代码行数:23,代码来源:CustomerCreate.cs

示例14: Main

        static void Main(string[] args)
        {
            DesiredCapabilities capability = null;
            IWebDriver driver = null;
            for (int i = 1; i < 4; i++)
            {
                switch (i)
                {
                    case 1:
                        capability = DesiredCapabilities.Firefox();
                        capability.SetCapability("BrowserName", "firefox");
                        break;
                    case 2:
                        capability = DesiredCapabilities.Chrome();
                        capability.SetCapability("BrowserName", "chrome");
                        break;
                    case 3:
                        capability = DesiredCapabilities.InternetExplorer();
                        capability.SetCapability("BrowserName", "internet explorer");
                        break;
                    default:
                        return;
                }

                driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
                driver.Manage().Window.Maximize();
                driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
                driver.Navigate().GoToUrl("http://www.baidu.com");
                IWebElement searchBox = driver.FindElement(By.Id("kw"));
                IWebElement searchButton = driver.FindElement(By.Id("su"));
                searchBox.SendKeys("Shinetech");
                searchButton.Click();
                driver.Dispose();
            }
        }
开发者ID:TylerTan,项目名称:SeleniumGridDemo,代码行数:36,代码来源:Program.cs

示例15: Should_be_able_to_read_text_from_label_when_content_is_more_than_just_text

        public void Should_be_able_to_read_text_from_label_when_content_is_more_than_just_text()
        {
            var pagePath = Path.Combine(Environment.CurrentDirectory, "markup.html");

            driver = new FirefoxDriver();
            driver.Navigate().GoToUrl(pagePath);

            var container = driver.FindElement(By.ClassName("some-class"));
            var labels = container.FindElements(By.TagName("label"));

            // This works:
            Assert.That(labels[0].GetAttribute("class"), Is.EqualTo("some-other-class"));

            // But not this:
            Assert.That(labels[0].Text, Is.EqualTo("Alla kommuner"));
        }
开发者ID:archive,项目名称:sandbox,代码行数:16,代码来源:ProblemWithLabelSpecs.cs


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