本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElementByTagName方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElementByTagName方法的具体用法?C# ChromeDriver.FindElementByTagName怎么用?C# ChromeDriver.FindElementByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElementByTagName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Scrape
private IEnumerable<Domain.Product> Scrape(string postcode)
{
var output = new List<Domain.Product>();
using (var driver = new ChromeDriver())
{
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl("http://www.dominos.co.uk");
driver.FindElementById("txtPostcode").SendKeys(postcode);
driver.FindElementById("btnStoreSearch").Click();
Thread.Sleep(1000);
driver.FindElementByCssSelector(".btn-secondary").Click();
Thread.Sleep(1000);
driver.Navigate().GoToUrl("https://www.dominos.co.uk/ProductCatalog/GetStoreContext");
string storeContextJson = driver.FindElementByTagName("pre").Text;
var storeContext = JsonConvert.DeserializeObject<StoreContext>(storeContextJson);
driver.Navigate().GoToUrl(
$"https://www.dominos.co.uk/ProductCatalog/GetStoreCatalog?collectionOnly={storeContext.SessionContext.CollectionOnly}&menuVersion={storeContext.SessionContext.MenuVersion}&storeId={storeContext.SessionContext.StoreId}");
string storeCatalogJson = driver.FindElementByTagName("pre").Text;
var products = JsonConvert.DeserializeObject<List<DTOs.Category>>(storeCatalogJson);
output = products
.SelectMany(p => p.Subcategories)
.SelectMany(p => p.Products)
.Where(p => !p.IsAlcohol)
.Where(p => p.Type != "PizzaLegend")
.Where(p => p.Name != "Half & Half")
.Where(p => p.Name != "Create Your Own")
.Select(p => new Domain.Product()
{
Id = p.Id.ToString(),
Name = p.Name,
Description = p.Description,
ImageUrl = p.ImageUrl.Replace("256x256", "1024x1024"),
GlutenFree = p.IsGlutenFree,
Hot = p.IsHot,
Vegetarian = p.IsVegetarian,
Price = p.DisplayPrice,
Category = (ProductCategory)Enum.Parse(typeof(ProductCategory), p.Type)
})
.ToList();
}
return output;
}