本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElement方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElement方法的具体用法?C# ChromeDriver.FindElement怎么用?C# ChromeDriver.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElement方法的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: 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();
}
示例3: TestWithImplicitWait
public void TestWithImplicitWait()
{
//Go to the Demo AjAX Application
IWebDriver driver = new ChromeDriver(@"C:\ChromeDriver");
driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/AjaxDemo.html");
//Set the Implicit Wait time Out to 10 Seconds
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
try {
//Get link for Page 4 and click on it
IWebElement page4button = driver.FindElement(By.LinkText("Page 4"));
page4button.Click();
//Get an element with id page4 and verify it's text
IWebElement message = driver.FindElement(By.Id("page4"));
Assert.IsTrue(message.Text.Contains("Nunc nibh tortor"));
}
catch (NoSuchElementException e)
{
Assert.Fail("Element not found!!");
}
finally
{
driver.Close();
}
}
示例4: TestWTCDateTimePicker
public void TestWTCDateTimePicker()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.wtc.nl/");
SeleniumSetMethods.EnterText(driver, "arrival1", "santiago", By.Name);
SeleniumSetMethods.EnterText(driver, "arrival1", Keys.Tab, By.Name);
SeleniumSetMethods.Click(driver, "departureDate1", "Id");
var test = driver.FindElement(By.ClassName("ui-datepicker-calendar"));
var tds = test.FindElements(By.TagName("td"));
var departureDate = tds.Where(td => td.Text == "25").FirstOrDefault();
departureDate.Click();
Thread.Sleep(1000);
SeleniumSetMethods.Click(driver, "departureDate2", "Id");
var calendar2 = driver.FindElement(By.ClassName("ui-datepicker-calendar"));
tds = calendar2.FindElements(By.TagName("td"));
var returnDate = tds.Where(td => td.Text == "30").LastOrDefault();
returnDate.Click();
Thread.Sleep(1000);
SeleniumSetMethods.Click(driver, "search_btn", "Id");
Thread.Sleep(30000);
//todo maak get methodes, om validaties te controleren
driver.Quit();
}
示例5: Should_page_through_items_in_chrome
public void Should_page_through_items_in_chrome()
{
IWebDriver chromeDriver = new ChromeDriver(TestContext.CurrentContext.TestDirectory);
chromeDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
chromeDriver.Navigate().GoToUrl("http://localhost:1392/");
Login(chromeDriver);
chromeDriver.FindElement(By.LinkText("Orders")).Click();
for (int i = 0; i < 82; i++)
{
IWebElement nextButton = chromeDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_ImageButtonNext"));
nextButton.Click();
IWebElement pageCount = chromeDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_TextBoxPage"));
int pageNumber = int.Parse(pageCount.GetAttribute("value"));
Assert.AreEqual(i + 2, pageNumber);
}
chromeDriver.FindElement(By.Id("LoginStatus1")).Click(); ;
chromeDriver.Quit();
}
示例6: Can_Register_User
public void Can_Register_User()
{
string chromeDriverDirectory = string.Format(@"{0}\..\..\..\tools", Directory.GetCurrentDirectory());
IWebDriver driver = new ChromeDriver(chromeDriverDirectory);
driver.Navigate().GoToUrl("http://localhost:64872/Account/Register");
string username = string.Format("testuser{0}", DateTime.Now.Ticks);
IWebElement userNameField = driver.FindElement(By.Id("UserName"));
userNameField.SendKeys(username);
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();
IWebElement loginName = driver.FindElement(By.LinkText(string.Format("Hello {0}!", username)));
Assert.IsTrue(loginName.Displayed);
driver.Quit();
}
示例7: 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();
}
示例8: CanLoadWebPageTest
public void CanLoadWebPageTest()
{
// add the directory containing chromedriver.exe to PATH
var driver = new ChromeDriver();
var baseURL = "http://localhost:6917/";
try
{
driver.Navigate().GoToUrl(baseURL + "/");
driver.FindElement(By.Id("Name")).Clear();
driver.FindElement(By.Id("Name")).SendKeys("Test");
new SelectElement(driver.FindElement(By.Id("Color"))).SelectByText("Red");
driver.FindElement(By.CssSelector("option[value=\"Red\"]")).Click();
driver.FindElement(By.CssSelector("input.btn")).Click();
var element = driver.FindElement(By.Name("PreviousNames[0].FirstName"), 3);
element.Clear();
driver.FindElement(By.Name("PreviousNames[0].FirstName")).SendKeys("ONe");
driver.FindElement(By.Name("PreviousNames[0].Surname")).Clear();
driver.FindElement(By.Name("PreviousNames[0].Surname")).SendKeys("Two");
var screenshot = driver.GetScreenshot();
screenshot.SaveAsFile("screenshot.png", ImageFormat.Png);
driver.FindElement(By.CssSelector("input.btn.btn-success")).Click();
}
catch (Exception)
{
Screenshot screenshot = driver.GetScreenshot();
screenshot.SaveAsFile("screenshot-error.png", ImageFormat.Png);
throw;
}
driver.Quit();
}
示例9: GetData
//碳结圆钢价格行情
public static void GetData(string linkName, int marketId)
{
IWebDriver driver = new ChromeDriver();
try
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.mysteel.com/");
var userName = driver.FindElement(By.Name("my_username"));
userName.SendKeys("tx6215");
var password = driver.FindElement(By.Name("my_password"));
password.SendKeys("tx6215");
userName.Submit();
var steel = driver.FindElement(By.LinkText("结构钢"));
driver.Navigate().GoToUrl(steel.GetAttribute("href"));
Thread.Sleep(2000);
var carbonRound = driver.FindElement(By.LinkText("碳圆"));
driver.Navigate().GoToUrl(carbonRound.GetAttribute("href"));
Thread.Sleep(2000);
var date = DateTime.Now.Day + "日";
GetPage(driver, linkName, marketId);
}
finally
{
driver.Close();
driver.Quit();
}
}
示例10: InboxModel
public InboxModel(string username, string password, BackgroundWorker bw, bool tv)
{
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profileIB");
IWebDriver driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("http://www.inboxdollars.com");
try
{
driver.FindElement(By.Id("loginname")).Clear();
driver.FindElement(By.Id("pwd")).Clear();
driver.FindElement(By.Id("loginname")).SendKeys(username);
driver.FindElement(By.Id("pwd")).SendKeys(password);
Helpers.wait(1000);
driver.FindElement(By.ClassName("submit2")).Click();
}
catch { }
try
{
if (driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Text != "0")
{
driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Click();
}
}
catch { }
if (!tv)
{
try
{
driver.FindElement(By.ClassName("videos")).Click();
videos(driver);
}
catch { }
}
else if (tv)
{
try
{
driver.FindElement(By.ClassName("tv")).Click();
Helpers.wait(2000);
Helpers.ByClass(driver, "jw-icon");
while (true)
{
try
{
driver.FindElement(By.Id("tvStillTherePopupContinue")).Click();
}
catch { }
}
}
catch { }
}
}
示例11: Should_navigate_to_google
public void Should_navigate_to_google()
{
var ieDriver = new ChromeDriver(); //@"C:\Users\Jeroen van Menen\AppData\Local\Google\Chrome\Application");
ieDriver.Navigate().GoToUrl("http://www.google.com");
ieDriver.FindElement(By.Name("q")).SendKeys("WatiN meets WebDriver");
ieDriver.FindElement(By.Name("btnG")).Click();
ieDriver.Quit();
}
示例12: Scrape
public void Scrape()
{
KopipastaContext db = new KopipastaContext();
var posts = db.PostsUncreated.Where(x => x.Status == PostUnscrapedStatus.unscraped).Take(10).ToList();
//var posts = new List<PostUnscraped> { new PostUnscraped { Id = 0, SiteId = 1, Status = PostUnscrapedStatus.unscraped }, new PostUnscraped { Id = 1, SiteId = 2, Status = PostUnscrapedStatus.unscraped } };
List<Post> CreatedPosts = new List<Post>();
IWebDriver driver = new ChromeDriver(@"C:\Selenium\");
for (int i = 0; i < posts.Count(); i++)
{
var post = posts[i];
driver.Navigate().GoToUrl(baseUrl + post.SiteId);
try
{
log.Info("parsing post №: " + post.SiteId);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
string postTitle = wait.Until((d) => { return d.FindElement(By.CssSelector(titleSelector)).Text; });
string postBody = driver.FindElement(By.ClassName(bodySelector)).Text;
string postRating = ratingBase + post.SiteId;
int rating = int.Parse(driver.FindElement(By.Id(postRating)).Text);
string DateString = driver.FindElement(By.ClassName(postDate)).Text;
var ScrapedPost = new Post() { Body = postBody, Header = postTitle, Rating = rating, SiteId = post.SiteId, Created = DateString };
CreatedPosts.Add(ScrapedPost);
try
{
db.Posts.Add(ScrapedPost);
db.SaveChanges();
db.PostsUncreated.Remove(post);
}
catch (Exception ex)
{
log.Error("error saving post to db, post №: " + post.SiteId);
log.Error(ex.StackTrace);
}
}
catch (System.FormatException ex)
{
log.Error("error on parsing post rating, post №: " + post.SiteId);
log.Error(ex.StackTrace);
}
catch (Exception ex)
{
log.Error("error on scraping post №: " + post.SiteId);
log.Error(ex.StackTrace);
}
}
driver.Quit();
}
示例13: Test
public void Test()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://fourthqaportal.cloudapp.net/technicaltest/Account/Register");
driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("user_name");
driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys("[email protected]");
driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).SendKeys("password");
driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("password");
driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click();
}
示例14: Selenium_AboutPage
public void Selenium_AboutPage()
{
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl(this.baseURL);
driver.FindElement(By.LinkText("About")).Click();
var actual = driver.FindElement(By.CssSelector("P")).Text.Trim();
Assert.AreEqual("Fabrikam Fiber (c) 2014.", actual);
}
}
示例15: Main
static void Main(string[] args)
{
Data d = new Data();
IWebDriver driver = new ChromeDriver(@"E:\");
driver.Navigate().GoToUrl("https://mail.google.com");
IWebElement email = driver.FindElement(By.Id("Email"));
email.SendKeys(d.Login);
IWebElement pass = driver.FindElement(By.Id("Passwd"));
pass.SendKeys(d.password);
IWebElement sign = driver.FindElement(By.Id("signIn"));
sign.Click();
}