本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElements方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElements方法的具体用法?C# ChromeDriver.FindElements怎么用?C# ChromeDriver.FindElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public void Login(String loginUrl)
{
var options = new ChromeOptions();
options.AddArguments("--test-type", "--start-maximized");
options.AddArguments("--test-type", "--ignore-certificate-errors");
options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);
driver.Navigate().GoToUrl(loginUrl);
int timeout = 0;
while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
{
Thread.Sleep(1);
timeout++;
}
IWebElement element = driver.FindElement(By.ClassName("logbox"));
IWebElement ElName = element.FindElement(By.Name("username"));
ElName.Clear();
ElName.SendKeys(loginName);
IWebElement ElPassword = element.FindElement(By.Id("password"));
ElPassword.Clear();
ElPassword.SendKeys(loginPassword);
IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
ElLogin.Click();
}
示例2: GrindaModel
public GrindaModel(string username, string password, BackgroundWorker bw, bool openGrinda)
{
string numbers = "";
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profileGB");
IWebDriver driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("http://www.grindabuck.com/login");
try
{
driver.FindElement(By.Id("login_username")).SendKeys(username);
driver.FindElement(By.Id("pwd")).SendKeys(password);
driver.FindElement(By.ClassName("btn-lg")).Click();
}
catch { }
IList<IWebElement> smalls = driver.FindElements(By.TagName("small"));
foreach (IWebElement small in smalls)
{
if (small.Text.Contains("Last Checkin"))
{
numbers = small.Text;
break;
}
}
if (DateTime.Parse(numbers.Split(' ')[2]).DayOfYear != DateTime.Now.DayOfYear)
{
checkIn(driver);
}
}
示例3: ZoomModel
public ZoomModel(string username, string password, BackgroundWorker bw, bool justZoom)
{
bool looping = true;
while (looping)
{
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profileZB");
IWebDriver driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("http://members.grabpoints.com/#/login?email=" + username);
try
{
//driver.FindElement(By.Name("email")).SendKeys(username);
//driver.FindElement(By.Name("email")).SendKeys(Keys.Enter);
////Helpers.wait(5000);
driver.FindElement(By.Id("password")).SendKeys(password);
driver.FindElement(By.ClassName("btn-block")).Click();
}
catch { }
Helpers.wait(10000);
if (!justZoom)
{
try
{
int counter = 0;
IList<IWebElement> turnOffNotifcations = driver.FindElements(By.ClassName("btn-block"));
foreach (IWebElement turnOffNotication in turnOffNotifcations)
{
if (counter == turnOffNotifcations.Count - 1)
{
turnOffNotication.Click();
}
counter++;
}
}
catch { }
int hr = DateTime.Now.Hour;
try
{
driver.Navigate().GoToUrl("http://members.grabpoints.com/#/offers/watch_videos");
}
catch { }
while (!viroolBool)
{
try
{
System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
foreach (String window in windowHandles)
{
try
{
IWebDriver popup = driver.SwitchTo().Window(window);
}
catch { }
try
{
if (driver.Title.Contains("Facebook"))
{
driver.Close();
}
}
catch { }
try
{
IList<IWebElement> surveys = driver.FindElements(By.ClassName("btn-block"));
if (surveys.Count > 2)
{
driver.FindElement(By.ClassName("btn-block")).Click();
}
}
catch { }
if (!junVideos)
junVids(driver);
if (!volume)
volume11(driver);
if (volume && junVideos && !viroolBool)
virool(driver);
Helpers.wait(5000);
}
}
catch { }
}
Helpers.closeWindows(driver, titles);
driver.Close();
//.........这里部分代码省略.........
示例4: getWebElementsByXPath
/// <summary>
///
/// </summary>
/// <param name="chromeDriver"></param>
/// <param name="containerXPath"></param>
/// <param name="linkXPath"></param>
/// <returns></returns>
private List<IWebElement> getWebElementsByXPath(ChromeDriver chromeDriver, String containerXPath, String linkXPath)
{
try
{
// ищем все контейнеры, которые содержат containerXPath
List<IWebElement> webConteiners = chromeDriver.FindElements(By.XPath(containerXPath)).ToList();
if (webConteiners != null)
{
List<IWebElement> returnElements = new List<IWebElement>();
foreach (IWebElement t in webConteiners) // получаем все контейнеры
{
// нужно пробежать по всем контейнерам и сложить все элементы linkXPath в этих контейнерах
List<IWebElement> webLinks = t.FindElements(By.XPath(linkXPath)).ToList();
foreach (IWebElement l in webLinks)
{
returnElements.Add(l);
}
}
return returnElements;
}
}
catch (WebDriverException e)
{
System.Diagnostics.Trace.WriteLine(containerXPath + System.Environment.NewLine +
linkXPath + System.Environment.NewLine +
e.Message);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(containerXPath + System.Environment.NewLine +
linkXPath + System.Environment.NewLine +
e.Message);
}
return new List<IWebElement>(); // возвращаем пустой массив
}
示例5: CreateExcelFile
private static void CreateExcelFile(ChromeDriver driver)
{
var homeTeams = driver.FindElements(By.ClassName("team-home"));
var awayTeams = driver.FindElements(By.ClassName("team-away"));
var scores = driver.FindElements(By.ClassName("score"));
var wb = new XLWorkbook();
var ws = wb.Worksheets.Add("Scores");
ws.Cell("A1").Value = "Home Team";
ws.Cell("B1").Value = "Score";
ws.Cell("C1").Value = "Away Team";
for (int i = 0; i < homeTeams.Count; i++)
{
string homeTeam = homeTeams[i].Text;
string score = scores[i].Text;
string awayTeam = awayTeams[i].Text;
ws.Cell("A" + (i + 2)).Value = homeTeam;
ws.Cell("B" + (i + 2)).Value = score;
ws.Cell("C" + (i + 2)).Value = awayTeam;
}
// Beautify
ws.Range("A1:C1").Style.Font.Bold = true;
ws.Columns().AdjustToContents();
wb.SaveAs("../../../../FlashScore.xlsx");
}
示例6: Main
private static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver("C:\\");
driver.Navigate().GoToUrl("file:///C:/Users/anil.krishnamaneni/Desktop/New%20Text%20Document.html");
var coll = driver.FindElements(By.TagName("label"));
foreach (var label in coll)
{
if (label.Text.Trim() == "welcome to Ding")
{
label.Click();
break;
}
}
var alert = driver.WaitGetAlert();
IAlert a = driver.SwitchTo().Alert();
a.Accept();
driver.FindElement(By.TagName("Input")).Click();
a = driver.SwitchTo().Alert();
a.Accept();
driver.FindElement(By.ClassName("submit")).Click();
a = driver.SwitchTo().Alert();
a.Accept();
}
示例7: Search_BestValue
public void Search_BestValue()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.markandspencer.com");
IWebElement globalSearch = driver.FindElement(By.Id("global-search"));
globalSearch.SendKeys("Malbec");
globalSearch.SendKeys(Keys.Enter);
IList<IWebElement> elements = driver.FindElements(By.Xpath("//dd[@class='price1']"));
string price = "";
double min = Double.parseDouble(elements[0].getText().replace("£","").replace(",",""));
foreach (IWebElement child in elements)
{
price = child.getText().replace("£","").replace(",","");
double childPrice = Double.parseDouble(price);
if(childPrice < min)
{
min = childPrice;
}
}
System.out.println("best value wine: " + min);
driver.Quit();
}
示例8: Cannot_Register_User_With_Empty_Username
public void Cannot_Register_User_With_Empty_Username()
{
string chromeDriverDirectory = string.Format(@"{0}\..\..\..\tools", Directory.GetCurrentDirectory());
IWebDriver driver = new ChromeDriver(chromeDriverDirectory);
driver.Navigate().GoToUrl("http://localhost:64872/Account/Register");
IWebElement passwordField = driver.FindElement(By.Id("Password"));
passwordField.SendKeys("[email protected]");
IWebElement confirmPassword = driver.FindElement(By.Id("ConfirmPassword"));
confirmPassword.SendKeys("[email protected]");
IWebElement registerButton = driver.FindElement(By.ClassName("btn"));
registerButton.Click();
ReadOnlyCollection<IWebElement> errorMessages = driver.FindElements(By.XPath("//div[@class='validation-summary-errors']/ul/li"));
IWebElement errorMessage = errorMessages.FirstOrDefault();
Assert.IsNotNull(errorMessage);
Assert.AreEqual("The User name field is required.", errorMessage.Text);
driver.Quit();
}
示例9: GetSearchResultProductNunmbers
public List<string> GetSearchResultProductNunmbers(ChromeDriver driver)
{
var Products = new List<string>();
foreach (var nameEl in driver.FindElements(By.XPath("//img[@class='product-image']")))
{
Products.Add(nameEl.GetAttribute("alt").Split(' ').Last());
}
return Products;
}
示例10: Search_FiveStarsRating
public void Search_FiveStarsRating()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.markandspencer.com");
IWebElement globalSearch = driver.FindElement(By.Id("global-search"));
globalSearch.SendKeys("Malbec");
globalSearch.SendKeys(Keys.Enter);
IList<IWebElement> elements = driver.FindElements(By.Xpath("//span[@itemprop='ratingValue' and contains(@style,'width:100.0%')]"));
int fiveStars = elements.Count;//number of wines with 5 star ratings
System.out.println("number of wines with 5 star ratings: " + fiveStars);
driver.Quit();
}
示例11: Search_NumberOfMalbec
public void Search_NumberOfMalbec()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.markandspencer.com");
IWebElement globalSearch = driver.FindElement(By.Id("global-search"));// with "inspect element" I pick the "id" of the element
globalSearch.SendKeys("Malbec");
globalSearch.SendKeys(Keys.Enter);
IList<IWebElement> elements = driver.FindElements(By.Xpath("//h3[@class='body2' and contains(text()='Malbec')]"));
int malbecWines = elements.Count;//number of wines returned for a search on the word “malbec”
System.out.println("number of Malbec wines: " + malbecWines);
driver.Quit();
}
示例12: SuccessfulLogin
public void SuccessfulLogin()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-extensions");
options.AddArgument("--start-maximized");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://www.qa.way2automation.com/");
driver.FindElement(By.CssSelector("#load_form > h3"));
driver.FindElement(By.CssSelector("#load_form > div > div.span_3_of_4 > p > a[href='#login']")).Click();
driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(5) > input[name='username']")).SendKeys("j2bwebdriver");
driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(6) > input[name='password']")).SendKeys("j2bwebdriver");
driver.FindElements(By.CssSelector("#load_form > div > div.span_1_of_4 > input"))[1].Submit();
Thread.Sleep(3000);
Assert.IsFalse(driver.FindElement(By.CssSelector("body")).Text.Contains("Username"));
Assert.IsFalse(driver.FindElement(By.CssSelector("body")).Text.Contains("Password"));
driver.Close();
}
示例13: SetData
public static void SetData(int marketId,string linkText,bool isGoOn, int priceIndex)
{
IWebDriver driver = new ChromeDriver();
try
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.f139.com/");
var loginName = driver.FindElement(By.Id("userName"));
loginName.SendKeys("zh15295667405");
var loginPassword = driver.FindElement(By.Id("passWord"));
loginPassword.SendKeys("15295667405");
var loginBtn = driver.FindElement(By.ClassName("btn_login"));
loginBtn.Click();
var ferroalloyUrls = driver.FindElements(By.LinkText("废钢网"));
driver.Navigate().GoToUrl(ferroalloyUrls[0].GetAttribute("href"));
Thread.Sleep(2000);
var silicon = driver.FindElement(By.LinkText("数据"));
driver.Navigate().GoToUrl(silicon.GetAttribute("href"));
Thread.Sleep(2000);
var gc = driver.FindElement(By.LinkText("钢材"));
driver.Navigate().GoToUrl(gc.GetAttribute("href"));
Thread.Sleep(2000);
var linkName = driver.FindElement(By.LinkText(linkText));
driver.Navigate().GoToUrl(linkName.GetAttribute("href"));
Thread.Sleep(2000);
GetData(driver, marketId, isGoOn, priceIndex);
foreach (Price price in PriceList)
{
PriceHelper.SavePrice(price);
}
}
finally
{
driver.Close();
driver.Quit();
}
}
示例14: Run
//冶金焦、铸造焦
public void Run()
{
IWebDriver driver = new ChromeDriver();
try
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://data.f139.com/list.do?pid=3&vid=126");
var loginNames = driver.FindElements(By.Id("userName"));
if(loginNames.Count > 0)
{
var loginName = loginNames[0];
loginName.SendKeys("zh15295667405");
var loginPassword = driver.FindElement(By.Id("passWord"));
loginPassword.SendKeys("15295667405");
var loginBtn = driver.FindElement(By.Id("submitbtn"));
loginBtn.Click();
}
var divP = driver.FindElement(By.Id("thjprolist"));
var divs = divP.FindElements(By.TagName("div"));
var yCokeDiv = divs[8].FindElement(By.LinkText("冶金焦"));//冶金焦链接
//var zCokeDiv = divs[8].FindElement(By.LinkText("铸造焦"));//铸造焦链接
driver.Navigate().GoToUrl(yCokeDiv.GetAttribute("href"));
GetData(driver);
var divPz = driver.FindElement(By.Id("thjprolist"));
var divSz = divPz.FindElements(By.TagName("div"));
var zCokeDiv = divSz[8].FindElement(By.LinkText("铸造焦"));//铸造焦链接
driver.Navigate().GoToUrl(zCokeDiv.GetAttribute("href"));
GetData(driver);
foreach(Price price in PriceList)
{
PriceHelper.SavePrice(price);
}
}
finally {
driver.Close();
driver.Quit();
}
}
示例15: Login
public void Login()
{
var options = new ChromeOptions();
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.switches", (object)("--start-maxisized"));
options.AddArguments("--test-type", "--start-maximized");
options.AddArguments("--test-type", "--ignore-certificate-errors");
options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);
//var ieoptions = new InternetExplorerOptions();
//DesiredCapabilities iecapabilities = DesiredCapabilities.InternetExplorer();
//iecapabilities.SetCapability("internetexplorer.switches", (object)("--start-maxisized"));
//ieoptions.AddAdditionalCapability("--test-type", "--start-maximized");
//ieoptions.AddAdditionalCapability("--test-type", "--ignore-certificate-errors");
//var iedriver = new InternetExplorerDriver(@"C:\Program Files (x86)\Internet Explorer");
driver.Navigate().GoToUrl(loginurl);
int timeout = 0;
while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
{
Thread.Sleep(1);
timeout++;
}
IWebElement element = driver.FindElement(By.ClassName("logbox"));
IWebElement ElName = element.FindElement(By.Name("username"));
ElName.Clear();
ElName.SendKeys(loginName);
IWebElement ElPassword = element.FindElement(By.Id("password"));
ElPassword.Clear();
ElPassword.SendKeys(loginPassword);
IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
ElLogin.Click();
}