本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElementByCssSelector方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElementByCssSelector方法的具体用法?C# ChromeDriver.FindElementByCssSelector怎么用?C# ChromeDriver.FindElementByCssSelector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElementByCssSelector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuyOneProductSelenium
public void BuyOneProductSelenium()
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://localhost:5001");
var lightingCategoryLink = driver.FindElementByCssSelector(".category-menu > div:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(2) > a:nth-child(1)");
lightingCategoryLink.Click();
var lightingProduct = driver.FindElementByCssSelector("div.col-lg-3:nth-child(1) > div:nth-child(1) > a:nth-child(1)");
lightingProduct.Click();
var ProductLink = driver.FindElementByCssSelector(".btn");
Assert.IsNotNull(ProductLink);
}
示例2: Main
static void Main(string[] args)
{
var url = "https://qa-antigo.elefanteletrado.com.br/Account/Login";
var driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(url);
Thread.Sleep(2000);
var campoLogin = driver.FindElementById("name");
campoLogin.SendKeys("asdf");
Thread.Sleep(2000);
var botaoEntrar = driver.FindElementByCssSelector("input[type=submit][title='" + "Entrar" + "']");
botaoEntrar.Click();
Thread.Sleep(2000);
var mensagemInvalida = "Usuário não encontrado.";
var tagErro = driver.FindElementByClassName("error");
if (tagErro.Text != mensagemInvalida)
{
Console.WriteLine("Mensagem errada, veio: " + tagErro.Text + ", esperado: " + mensagemInvalida);
}
else
{
Console.WriteLine("Validação correta!");
}
}
示例3: 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;
}
示例4: NaverCrawler
public NaverCrawler()
{
string id = ConfigurationManager.AppSettings["id"];
string password = ConfigurationManager.AppSettings["password"];
var processList = Process.GetProcessesByName("chromedriver");
foreach( var process in processList )
{
process.Kill();
}
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var option = new ChromeOptions();
option.AddExtension("3.7_0.crx");
driver = new ChromeDriver(chromeDriverService, option );
while (driver.WindowHandles.Count < 2)
{
Thread.Sleep(100);
}
driver.SwitchTo().Window(driver.WindowHandles[1]);
WebDriverWait _wait = new WebDriverWait(driver, new TimeSpan(0, 1, 0));
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));
_wait.Until(d => d.FindElement(By.Id("user_email")));
driver.FindElementById("user_email").SendKeys(String.Format("{0}@naver.com\n", id));
_wait.Until(d => d.FindElement(By.Id("user_password")));
driver.FindElementById("user_password").SendKeys(password);
driver.FindElementById("loginbtn").Click();
driver.SwitchTo().Window(driver.WindowHandles[0]);
driver.Url = loginFormUrl;
driver.FindElementByCssSelector("#id").SendKeys(id);
driver.FindElementByCssSelector("#pw").SendKeys(password);
driver.FindElementByCssSelector("input.int_jogin").Click();
cookieContainer = new CookieContainer();
ReadOnlyCollection<OpenQA.Selenium.Cookie> cookieCollections = null;
bool sessionFound = false;
while (!sessionFound)
{
cookieCollections = driver.Manage().Cookies.AllCookies;
foreach( var cookie in cookieCollections )
{
if ( cookie.Name == "JSESSIONID" )
{
sessionFound = true;
break;
}
}
}
foreach( var cookie in cookieCollections )
{
cookieContainer.Add(new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
}
driver.Quit();
}