本文整理汇总了C#中OpenQA.Selenium.IE.InternetExplorerDriver.FindElementByCssSelector方法的典型用法代码示例。如果您正苦于以下问题:C# InternetExplorerDriver.FindElementByCssSelector方法的具体用法?C# InternetExplorerDriver.FindElementByCssSelector怎么用?C# InternetExplorerDriver.FindElementByCssSelector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.IE.InternetExplorerDriver
的用法示例。
在下文中一共展示了InternetExplorerDriver.FindElementByCssSelector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBookSearch
public void TestBookSearch()
{
//First step is browse to website and go to search page.
System.IO.File.WriteAllText("result.txt","");
driver = new InternetExplorerDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("paratabplus.cloudapp.net");
driver.FindElementByClassName("menulist").FindElement(By.CssSelector("li a[href=\"/BookSearch/\"]")).Click();
Assert.AreEqual("Search", driver.Title);
IWebElement form;
//-----------------------------------
/* Next step is find book from define keywords then submit
* measure time from result that display in grey character on find result(if search result is found.)
* record it and use these measure data to summarize.
*/
driver.FindElementByName("Keyword").Clear();
driver.FindElementByName("Keyword").SendKeys("COM-FL2-2812");
driver.FindElementByTagName("select").Click();
driver.Keyboard.SendKeys(Keys.Down);
driver.Keyboard.SendKeys(Keys.Enter);
form = driver.FindElementByCssSelector("form[action=\"/BookSearch/Basic\"]");
form.Submit();
AssertSearchResult("Call no:COM-FL2-2812");
driver.FindElementByName("Keyword").Clear();
driver.FindElementByName("Keyword").SendKeys("Computer");
driver.FindElementByTagName("select").Click();
driver.Keyboard.SendKeys(Keys.Down);
driver.Keyboard.SendKeys(Keys.Enter);
form = driver.FindElementByCssSelector("form[action=\"/BookSearch/Basic\"]");
form.Submit();
AssertSearchResult("Bookname:Computer");
driver.FindElementByName("Keyword").Clear();
driver.FindElementByName("Keyword").SendKeys("James");
driver.FindElementByTagName("select").Click();
driver.Keyboard.SendKeys(Keys.Down);
driver.Keyboard.SendKeys(Keys.Enter);
form = driver.FindElementByCssSelector("form[action=\"/BookSearch/Basic\"]");
form.Submit();
AssertSearchResult("Author:James");
driver.FindElementByName("Keyword").Clear();
driver.FindElementByName("Keyword").SendKeys("shogakukan");
driver.FindElementByTagName("select").Click();
driver.Keyboard.SendKeys(Keys.Down);
driver.Keyboard.SendKeys(Keys.Enter);
form = driver.FindElementByCssSelector("form[action=\"/BookSearch/Basic\"]");
form.Submit();
AssertSearchResult("Publisher:shogakukan");
driver.FindElementByName("Keyword").Clear();
driver.FindElementByName("Keyword").SendKeys("1995");
driver.FindElementByTagName("select").Click();
driver.Keyboard.SendKeys(Keys.Down);
driver.Keyboard.SendKeys(Keys.Enter);
form = driver.FindElementByCssSelector("form[action=\"/BookSearch/Basic\"]");
form.Submit();
AssertSearchResult("Year:1995");
//-----------------------------------
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").SendKeys("NOV");
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").SendKeys("Sword Art Online Aincrad");
driver.FindElementByCssSelector("form input[placeholder=\"Author\"]").SendKeys("Reki Kawahara");
driver.FindElementByCssSelector("form input[placeholder=\"Publisher\"]").SendKeys("Zenshu");
driver.FindElementByCssSelector("form[action=\"/BookSearch/Advance\"] input[type=\"submit\"]").Click();
AssertSearchResult("\r\nCall no:NOV\r\nBookname:Sword Art Online Aincrad\r\nAuthor:Reki Kawahara\r\n" +
"Publisher:Zenshu\r\nYear:null");
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").Clear();
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").SendKeys("PE-FL1-0005");
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").SendKeys("Football training");
driver.FindElementByCssSelector("form input[placeholder=\"Author\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Author\"]").SendKeys("Graham Taylor");
driver.FindElementByCssSelector("form input[placeholder=\"Publisher\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Publisher\"]").SendKeys("Leopard Books");
driver.FindElementByCssSelector("form input[placeholder=\"Year\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Year\"]").SendKeys("1995");
driver.FindElementByCssSelector("form[action=\"/BookSearch/Advance\"] input[type=\"submit\"]").Click();
AssertSearchResult("\r\nCall no:PE-FL1-0005\r\nBookname:Football training\r\nAuthor:Graham Taylor\r\n" +
"Publisher:Leopard Books\r\nYear:1995");
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").Clear();
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").SendKeys("MAT");
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").SendKeys("Theory of computation");
driver.FindElementByCssSelector("form input[placeholder=\"Author\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Author\"]").SendKeys("รศ.ดร.เกียรติกูล เจียรนัยธนะกิจ");
driver.FindElementByCssSelector("form input[placeholder=\"Publisher\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Year\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Year\"]").SendKeys("2009");
driver.FindElementByCssSelector("form[action=\"/BookSearch/Advance\"] input[type=\"submit\"]").Click();
AssertSearchResult("\r\nCall no:MAT\r\nBookname:Theory of computation\r\nAuthor:รศ.ดร.เกียรติกูล เจียรนัยธนะกิจ\r\n" +
"Publisher:null\r\nYear:2009");
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").Clear();
driver.FindElementByCssSelector("input[type=\"text\"][name=\"CallNumber\"]").SendKeys("NOV");
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").Clear();
driver.FindElementByCssSelector("form input[placeholder=\"Book name\"]").SendKeys("นิทาน");
//.........这里部分代码省略.........
示例2: Donate_error_test
public void Donate_error_test()
{
RemoteWebDriver driver = new InternetExplorerDriver();
// Navigate to the base url.
driver.Navigate().GoToUrl(@"http://en.wikipedia.org");
// Main Page
var lnkDonate = driver.FindElementByCssSelector(@"a[title='Support us']");
lnkDonate.Click();
// Donate Page
var rbtnDonate50 = driver.FindElementByCssSelector(@"input[name='amount'][value='50']");
rbtnDonate50.Click();
var btnMakeDonation = driver.FindElementByCssSelector(@"input[value='Donate by credit/debit card']");
btnMakeDonation.Click();
// Donation Payments
var txtFirstName = driver.FindElementByName("fname");
var txtLastName = driver.FindElementByName("lname");
var txtStreet = driver.FindElementByName("street");
var txtPostalCode = driver.FindElementByName("zip");
var txtCity = driver.FindElementByName("city");
var txtEmailAddress = driver.FindElementByName("emailAdd");
var rbtnCardVisa = driver.FindElementByCssSelector(@"input[name='cardtype'][value='visa']");
txtFirstName.Clear();
txtFirstName.SendKeys("Vasya");
txtLastName.Clear();
txtLastName.SendKeys("Pupkin");
txtStreet.Clear();
txtStreet.SendKeys("Blah blah blah street");
txtPostalCode.Clear();
txtPostalCode.SendKeys("8577");
txtCity.Clear();
txtCity.SendKeys("My Str");
txtEmailAddress.Clear();
txtEmailAddress.SendKeys("[email protected]");
rbtnCardVisa.Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
var frameCardNumber=wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(@"iframe[src^='https://na.gcsip.com/orb/']")));
driver.SwitchTo().Frame(frameCardNumber);
var txtName = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("CREDITCARDNUMBER")));
txtName.Clear();
txtName.SendKeys("4556767453966453");
var ddlMonthSelect = new SelectElement(driver.FindElementByName(@"EXPIRYDATE_MM"));
var ddlYearSelect = new SelectElement(driver.FindElementByName(@"EXPIRYDATE_YY"));
var txtSecurityCode = driver.FindElementByName(@"CVV");
var btnContinue = driver.FindElementById("btnSubmit");
ddlMonthSelect.SelectByText("05");
ddlYearSelect.SelectByText("15");
txtSecurityCode.SendKeys("555");
Assert.IsTrue(btnContinue.Displayed, "There is a Continue button");
btnContinue.SendKeys(Keys.Enter);
driver.SwitchTo().DefaultContent();
wait.Until(ExpectedConditions.TitleContains(@"Donate-error - Payments"));
var lblFirstHeader = driver.FindElementById(@"firstHeading");
Assert.AreEqual("Donate-error", lblFirstHeader.Text);
}
示例3: Test_for_donation_error_text
public void Test_for_donation_error_text()
{
RemoteWebDriver Driver = new InternetExplorerDriver();
Driver.Navigate().GoToUrl(@"http://en.wikipedia.org/");
// On Main Page
var lnkSupportUs = Driver.FindElementByCssSelector(@"a[title='Support us']");
lnkSupportUs.Click();
// On Make your donation page
var radio50UAH = Driver.FindElementByCssSelector(@"#input_amount_0[value='50']");
radio50UAH.Click();
// And clich on "Donate" button
var btnDonate = Driver.FindElementByCssSelector(@"input[value='Donate by credit/debit card']");
btnDonate.Click();
// On Billing information
var txtFirstName = Driver.FindElementByName("fname");
var txtLastName = Driver.FindElementByName("lname");
var txtStreet = Driver.FindElementByName("street");
var txtPostalCode = Driver.FindElementByName("zip");
var txtCity = Driver.FindElementByName("city");
var txtEmailAddress = Driver.FindElementByName("emailAdd");
var radioCardType = Driver.FindElementByCssSelector(@"input[name='cardtype'][value='visa']");
txtFirstName.Clear();
txtFirstName.SendKeys("Vasya");
txtLastName.Clear();
txtLastName.SendKeys("Poopkin");
txtCity.Clear();
txtCity.SendKeys("Kyiv");
txtEmailAddress.Clear();
txtEmailAddress.SendKeys("[email protected]");
txtPostalCode.Clear();
txtPostalCode.SendKeys("80999");
txtStreet.Clear();
txtStreet.SendKeys("It is very boring");
radioCardType.Click();
// Donation form second part
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
string frameSelector = @"div#payment > iframe";
wait.Until(ExpectedConditions.ElementExists(By.CssSelector(frameSelector)));
var frameFormSecondPart = Driver.FindElementByCssSelector(frameSelector);
Driver.SwitchTo().Frame(frameFormSecondPart);
string cardNumSelector = @"CREDITCARDNUMBER";
wait.Until(ExpectedConditions.ElementIsVisible(By.Name(cardNumSelector)));
var txtCreditCardNum = Driver.FindElementByName(cardNumSelector);
var selectExpMonth = new SelectElement(Driver.FindElementByName(@"EXPIRYDATE_MM"));
var selectExpYear = new SelectElement(Driver.FindElementByName(@"EXPIRYDATE_YY"));
var txtCVV = Driver.FindElementByName(@"CVV");
var btnSubmit = Driver.FindElementById(@"btnSubmit");
txtCreditCardNum.Clear();
txtCreditCardNum.SendKeys("4716699955349929");
selectExpMonth.SelectByText("02");
selectExpYear.SelectByText("15");
txtCVV.Clear();
txtCVV.SendKeys("555");
// Looks like we cannot click on this button.
// Well...
btnSubmit.SendKeys(Keys.Enter);
Driver.SwitchTo().DefaultContent();
// On Donate result page
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(@"div#mw-content-text * big > span")));
var lblTransactionErrorMessage = Driver.FindElement(By.CssSelector(@"div#mw-content-text * big > span"));
Assert.AreEqual("Your transaction could not be accepted.", lblTransactionErrorMessage.Text);
Driver.Dispose();
}
示例4: TestMethod1
public void TestMethod1()
{
//RemoteWebDriver Driver = new InternetExplorerDriver();
RemoteWebDriver Driver = new InternetExplorerDriver();
//Driver.Url = "www.football.ua";
Driver.Navigate().GoToUrl(@"http://en.wikipedia.org/");
//Driver.Manage().Window.Maximize();
var lnkSupportUs = Driver.FindElementByCssSelector(@"a[title = 'Support us']");
lnkSupportUs.Click();
// Cannot find with this locator!
var radio50UAH = Driver.FindElementByXPath("/html/body/div[3]/div[2]/div[3]/table/tbody/tr/td[2]/form/div/div[3]/table/tbody/tr[1]/td[1]/label");//Driver.FindElementById("input_amount_0");// Driver.FindElementByCssSelector(@"#input_amount_0[value='50']");
radio50UAH.Click();
var btnDonate = Driver.FindElement(By.ClassName("payment-method-button"));
btnDonate.Click();
var txtFirstName = Driver.FindElementById("fname");
var txtlastName = Driver.FindElementById("lname");
var txtEmail = Driver.FindElementById("emailAdd");
var radioCardType = Driver.FindElementById("cc-visa");
txtFirstName.Clear();
txtFirstName.SendKeys("Vasya");
txtlastName.Clear();
txtlastName.SendKeys("Poopkin");
txtEmail.Clear();
txtEmail.SendKeys("[email protected]");
radioCardType.Click();
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(6));
var txtCreditCardNum = Driver.FindElementByName("CREDITCARDNU");
var selectExpMonth = new SelectElement(Driver.FindElementById("F1010_MM"));
var selectExpYear = new SelectElement(Driver.FindElementById("F1010_YY"));
var txtCVV = Driver.FindElementById(@"F1136");
var btnSubmit = Driver.FindElementById(@"btnSubmit");
txtCreditCardNum.Clear();
txtCreditCardNum.SendKeys("8975397698238467");
selectExpMonth.SelectByText("02");
selectExpYear.SelectByText("15");
txtCVV.Clear();
txtCVV.SendKeys("836");
btnSubmit.SendKeys(Keys.Enter);
Driver.SwitchTo().DefaultContent();
// On Donate results page
string headerSelector = @"h1.firstHeading";
var headingElement = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector(headerSelector)));
Assert.AreEqual("Donate-error", headingElement.Text);
Driver.Quit();
Driver.Dispose();
}