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


C# RemoteWebDriver.FindElements方法代码示例

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


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

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

示例2: DeletesAndAddsShouldBeEvidentOnRefresh

		static void DeletesAndAddsShouldBeEvidentOnRefresh( 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, "tag" );

				// Once the 'Add New Tag' button becomes enabled, we know that all tags have been loaded
				WebDriverWait shortWait = new WebDriverWait( driver, TimeSpan.FromSeconds( 2 ) );
				shortWait.Until( d => d.FindElement( By.Id( "add_new_tag" ) ).Enabled );
				//TODO TP 1650 - an enabled 'Add New Tag' button doesn't guarantee that the rendering is finished in Chrome; doing some unconditional wait...
				Thread.Sleep( 1000 );

				// Delete all except the first (if there is one)
				foreach ( IWebElement item in driver.FindElements( By.CssSelector( "button.delete" ) ).Skip( 1 ) )
					item.Click();

				shortWait.Until( d => d.FindElements( By.CssSelector( "input.tag_name" ) ).Count <= 1 );

				// Add a fresh one; give it a name
				driver.FindElement( By.Id( "add_new_tag" ) ).Click();
				var newTagInputElement = driver.FindElements( By.CssSelector( "input.tag_name" ) ).Last();
				newTagInputElement.Clear();
				newTagInputElement.Click();
				var newTagName = new Fixture().CreateAnonymous<string>();
				newTagInputElement.SendKeys( newTagName );

				string[] tagsAsSubmitted = SaveAndRecordSubmittedTags( driver );

				// Need a retry in case the initial load loads data which does not include the (eventually consistent) changes
				new WebDriverWaitIgnoringNestedTimeouts( driver, TimeSpan.FromSeconds( 7 ) ).Until( _ =>
				{
					driver.Navigate().Refresh();
					// Verify reloading the page shows the same tags pretty quickly
					return shortWait.Until( d =>
						d.FindElement( By.Id( "add_new_tag" ) ).Enabled
						&& tagsAsSubmitted.SequenceEqual( d.FindElements( By.CssSelector( "input.tag_name" ) ).Select( tagNameEl => tagNameEl.GetAttribute( "value" ).Trim() ) ) );
				} );
			}
		}
开发者ID:InishTech,项目名称:Sp.Api,代码行数:39,代码来源:AdminTags.cs

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

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

示例5: FindPrice

        public void FindPrice()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());

            //超級商城
            driver.Navigate().GoToUrl("https://tw.mall.yahoo.com/");

            driver.FindElement(By.XPath("//*[@id=\"srp-ac-bar\"]")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"UHSearchProperty\"]")).Click();

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

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

                try
                {
                    if (driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Text == "下一頁")
                    {
                        driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Click();
                    }
                    else
                    {
                        break;
                    }

                    products.Clear();
                    Thread.Sleep(1000);
                }
                catch (NoSuchElementException e)
                {
                    break;
                }
            }

            //購物中心
            driver.Navigate().GoToUrl("https://tw.buy.yahoo.com/");
            driver.FindElement(By.XPath("//*[@id=\"srp-ac-bar\"]")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"UHSearchProperty\"]")).Click();
            List<IWebElement> buyproducts = driver.FindElements(By.XPath("//*[@id=\"srp_result_list\"]/div/div/div[1]/a")).ToList();

            for (; ; )
            {
                List<IWebElement> products = driver.FindElements(By.XPath("//*[@id=\"srp_result_list\"]/div/div/div[1]/a")).ToList();
                foreach (var product in buyproducts)
                {
                    ReadProductDetailBuy(product.GetAttribute("href"), ref info);
                }

                try
                {
                    if (driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Text == "下一頁")
                    {
                        driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Click();
                    }
                    else
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                catch (NoSuchElementException e)
                {
                    break;
                }
            }

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


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