public FindElement ( By by ) : IWebElement | ||
by | By | By mechanism for finding the element. |
Результат | IWebElement |
static void Main(string[] args) { //Create an instance of HTTPWatch Controller Controller control = new Controller(); //Start IE Driver. IE Driver Server is located in C:\\ IWebDriver driver = new InternetExplorerDriver(@"C:\"); // Set a unique initial page title so that HttpWatch can attach to it string uniqueTitle = Guid.NewGuid().ToString(); IJavaScriptExecutor js = driver as IJavaScriptExecutor; js.ExecuteScript("document.title = '" + uniqueTitle + "';"); // Attach HttpWatch to the instance of Internet Explorer created through WebDriver Plugin plugin = control.AttachByTitle(uniqueTitle); //Open the HTTPWatch Window plugin.OpenWindow(false); //Navigate to the BMI Application Page driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/bmicalculator.html"); //Perform some steps driver.FindElement(By.Id("heightCMS")).SendKeys("181"); driver.FindElement(By.Id("weightKg")).SendKeys("80"); driver.FindElement(By.Id("Calculate")).Click(); //Export the HAR Log generated to a file plugin.Log.Save(@"C:\bmicalc.hwl"); //Close the Internet Explorer driver.Close(); }
public void Should_page_through_items_in_IE() { IWebDriver ieDriver = new InternetExplorerDriver(); ieDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); ieDriver.Navigate().GoToUrl("http://localhost:1392/"); Login(ieDriver); ieDriver.FindElement(By.LinkText("Orders")).Click(); for (int i = 0; i < 20; i++) { IWebElement nextButton = ieDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_ImageButtonNext")); nextButton.Click(); IWebElement pageCount = ieDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_TextBoxPage")); int pageNumber = int.Parse(pageCount.GetAttribute("value")); Assert.AreEqual(i + 2, pageNumber); } ieDriver.FindElement(By.Id("LoginStatus1")).Click(); ieDriver.Quit(); }
public void when_logging_in_with_an_invalid_username_and_password() { var capabilities = new DesiredCapabilities(); capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); var driver = new InternetExplorerDriver(capabilities); try { driver.Navigate().GoToUrl("http://*****:*****@user.com"); driver.FindElement(By.Name("Password")).SendKeys("BadPass"); driver.FindElement(By.TagName("form")).Submit(); driver.Url.ShouldEqual("http://localhost:52125/Account/LogOn"); driver.FindElement(By.ClassName("validation-summary-errors")).Text.ShouldContain( "The user name or password provided is incorrect."); } finally { driver.Close(); } }
static void Main(string[] args) { try { var stopWatch = Stopwatch.StartNew(); DesiredCapabilities capabilities = new DesiredCapabilities(); var driverService = ChromeDriverService.CreateDefaultService(@"E:\"); driverService.HideCommandPromptWindow = true; var webDriver = new InternetExplorerDriver(); webDriver.Navigate().GoToUrl("http://www.udebug.com/UVa/10812"); IWebElement inputBox = webDriver.FindElement(By.Id("edit-input-data")); inputBox.SendKeys("3\n2035415231 1462621774\n1545574401 1640829072\n2057229440 1467906174"); IWebElement submitButton = webDriver.FindElement(By.Id("edit-output")); submitButton.SendKeys("\n"); submitButton.Click(); string answer = webDriver.PageSource; int begin = answer.IndexOf("<pre>") + 5; answer = answer.Substring(begin, answer.IndexOf("</pre>") - begin); Console.WriteLine(answer); webDriver.Close(); Console.WriteLine(stopWatch.ElapsedMilliseconds); } catch (Exception exception) { Console.WriteLine(exception.Message); } }
public void logging_in_with_invalid_credentials() { var capabilities = new DesiredCapabilities(); capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); var driver = new InternetExplorerDriver(capabilities); driver.Navigate().GoToUrl(TargetAppUrl + "/Authentication/LogOff"); try { driver.Navigate().GoToUrl(TargetAppUrl + "/LogOn"); driver.FindElement(By.Name("EmailAddress")).SendKeys("*****@*****.**"); driver.FindElement(By.Name("Password")).SendKeys("BadPass"); driver.FindElement(By.TagName("form")).Submit(); driver.Url.ShouldEqual(TargetAppUrl + "/LogOn"); driver.FindElement(By.ClassName("validation-summary-errors")).Text.ShouldContain( "The user name or password provided is incorrect."); } finally { driver.Close(); } }
static void Main() { using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver()) { driver.Navigate().GoToUrl("https://www.bing.com/"); driver.FindElement(By.Id("sb_form_q")).SendKeys("Selenium WebDriver"); driver.FindElement(By.Id("sb_form_go")).Click(); Console.WriteLine("OK"); Console.ReadKey(intercept: true); } }
private static void crawlPartsbase() { IWebDriver driver = new InternetExplorerDriver(@"F:\IEDriverServer_x64_2.46.0"); driver.Navigate().GoToUrl("http://www.partsbase.com/landing/login.asp"); var usernameField = driver.FindElement(By.Name("username")); usernameField.SendKeys("tallaadmin"); var passwdField = driver.FindElement(By.Name("password")); passwdField.SendKeys("Ta11a2015!"); var submitBtn = driver.FindElement(By.XPath("//a[@class='btn btn-success' and @value='Log In']")); submitBtn.Click(); }
//tallaadmin //Ta11a2015! private static void CrawlILSmart() { IWebDriver driver = new InternetExplorerDriver(@"F:\IEDriverServer_x64_2.46.0"); driver.Navigate().GoToUrl("http://static.ilsmart.com/pages/ILSLogin2014.htm?TabId=56&language=en-US"); //<iframe src="http://static.ilsmart.com/pages/ILSLogin2014.htm?TabId=56&language=en-US" frameborder="0" style="width: 620px; height: 100px;" scrolling="no"></iframe> // <input tabindex="3" class="btn btn-primary btn-sm enter" type="submit" alt="Enter" value="Enter"> var usernameField = driver.FindElement(By.Name("username")); usernameField.SendKeys("c08hu01"); var passwdField = driver.FindElement(By.Name("password")); passwdField.SendKeys("Ta11a2015%"); var submitBtn = driver.FindElement(By.XPath("//input[@type='submit' and @value='Enter']")); submitBtn.Click(); }
public void when_logging_in_with_a_valid_username_and_password() { var options = new InternetExplorerOptions { IntroduceInstabilityByIgnoringProtectedModeSettings = true }; var driver = new InternetExplorerDriver(options); try { driver.Navigate().GoToUrl("http://*****:*****@user.com"); driver.FindElement(By.Name("Password")).SendKeys("RealPassword"); driver.FindElement(By.TagName("form")).Submit(); driver.Url.ShouldEqual("http://localhost:52125/"); } finally { driver.Close(); } }
public void OpenGoogle() { IWebDriver driver = new InternetExplorerDriver(); //IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Cheese"); System.Console.WriteLine("Page title is: " + driver.Title); // TODO add wait driver.Quit(); }
static void Main(string[] args) { IWebDriver driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl("http://e1.englishtown.com/partner/coolschool/Default.aspx"); IWebElement userNameQuery = driver.FindElement(By.Name("UserName")); IWebElement passwdQuery = driver.FindElement(By.Name("Password")); userNameQuery.SendKeys("cliu9800"); passwdQuery.SendKeys("pass"); IWebElement submitButton = driver.FindElement(By.Id("loginTrigger")); submitButton.Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(t => t.PageSource.ToLower().IndexOf("currentcourse") > 0); System.Console.WriteLine(string.Format("Page title is: {0}", driver.Title)); driver.Quit(); }
static void Main(string[] args) { // Please keep your IE configuration settings: // 1. Check on "Enable Protected Mode" at ALL zones in "Security" tab of Internet Options dialog. // 2. Browser zoom level keep to 100%. var ieOptions = new InternetExplorerOptions { // Uncomment these lines if you use Microsoft Edge IE mode. // AttachToEdgeChrome = true, // EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe", IgnoreZoomLevel = true, }; using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(ieOptions)) { driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3); driver.Navigate().GoToUrl("https://www.bing.com/"); driver.FindElement(By.Id("sb_form_q")).SendKeys("Selenium WebDriver"); driver.FindElement(By.ClassName("search")).Click(); Console.WriteLine("OK"); Console.ReadKey(intercept: true); } }
static void Main(string[] args) { var options = new InternetExplorerOptions { IgnoreZoomLevel = true }; IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(options); driver.Navigate().GoToUrl("https://www.tomasvasquez.com.br/blog"); IWebElement elemento = driver.FindElement(By.TagName("h1")); Console.WriteLine("O título do site é: {0}", elemento.Text); Console.Read(); driver.Quit(); }
static void Main(string[] args) { IWebDriver driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl("http://www.google.com"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("google test"); query.Submit(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(t => t.Title.ToLower().StartsWith("google test")); System.Console.WriteLine(string.Format("Page title is: {0}", driver.Title)); driver.Quit(); }
public void CanGetTweetsOnDefaultPage() { IWebDriver driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl("http://*****:*****@id='results']/li")); IList<IWebElement> accounts = driver.FindElements(By.XPath("//div[@id='summary']//tr")); //Assert.AreEqual(1, results.Count); Assert.IsTrue(results.Count > 0); //Assert.AreEqual(1, accounts.Count); Assert.IsTrue(accounts.Count > 1); // Close the browser //driver.Quit(); }
public void logging_in_with_no_credentials_displays_validation_error() { var capabilities = new DesiredCapabilities(); capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); var driver = new InternetExplorerDriver(capabilities); driver.Navigate().GoToUrl(TargetAppUrl + "/Authentication/LogOff"); try { driver.Navigate().GoToUrl(TargetAppUrl + "/LogOn"); driver.FindElement(By.TagName("form")).Submit(); driver.Url.ShouldEqual(TargetAppUrl + "/LogOn"); driver.FindElements(By.CssSelector("span.field-validation-error[data-valmsg-for=\"EmailAddress\"]")).ShouldNotBeEmpty(); driver.FindElements(By.CssSelector("span.field-validation-error[data-valmsg-for=\"Password\"]")).ShouldNotBeEmpty(); } finally { driver.Close(); } }
public AppDetail(InternetExplorerDriver ieDriver) { ProperyNames = new List<string>(); Properties = new List<string>(); var table = ieDriver.FindElement(By.ClassName("ms-formtable")); var rows = table.FindElements(By.TagName("tr")); foreach (var row in rows) { var cells = row.FindElements(By.TagName("td")); var propName = cells[0].Text; var links = cells[1].FindElements(By.TagName("a")); var prop = cells[1].Text; for (var i = 0; i < links.Count; i++) { var href = links[i].GetAttribute("href"); if(!href.Contains(Program.Domian)) continue; prop = prop.Replace(links[i].Text, "||(|)||" + href + "||()||" + links[i].Text + "||(|)||"); } ProperyNames.Add(propName); Properties.Add(prop); } }
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("*****@*****.**"); 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(); }
public void logging_in_with_valid_credentials_redirects_to_the_dashboard() { var capabilities = new DesiredCapabilities(); capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); var driver = new InternetExplorerDriver(capabilities); driver.Navigate().GoToUrl(TargetAppUrl + "/Authentication/LogOff"); try { driver.Navigate().GoToUrl(TargetAppUrl + "/LogOn"); driver.FindElement(By.Name("EmailAddress")).SendKeys("*****@*****.**"); driver.FindElement(By.Name("Password")).SendKeys("TestPassword01"); driver.FindElement(By.TagName("form")).Submit(); driver.Url.ShouldEqual(TargetAppUrl + "/"); } finally { driver.Close(); } }
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("*****@*****.**"); 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(); }
internal static string GetBillAmount(string userName, string password) { string retVal = "Unavailable"; //Clean up any previous instances Process[] testServerProcesses = Process.GetProcessesByName("IEDriverServer"); foreach (Process process in testServerProcesses) { process.Kill(); } Process[] ieProcesses = Process.GetProcessesByName("iexplore"); foreach (Process process in ieProcesses) { process.Kill(); } try { using (IWebDriver driver = new InternetExplorerDriver()) { driver.Navigate().GoToUrl("https://account.windowsazure.com/Subscriptions"); IWebElement usernameTB = null; IWebElement pwTB = null; try { usernameTB = driver.FindElement(By.Id("i0116")); } catch { retVal = "Username input not found."; } if (usernameTB != null) { usernameTB.SendKeys(userName); try { pwTB = driver.FindElement(By.Id("i0118")); } catch { retVal = "Password input not found."; } if (pwTB != null) { pwTB.SendKeys(TickerEncryption.Utility.Decrypt(password, Properties.Settings.Default.Thumb1, Properties.Settings.Default.Thumb2)); System.Threading.Thread.Sleep(5000); IWebElement loginBtn = driver.FindElement(By.Id("idSIButton9")); loginBtn.Click(); bool loggedInSuccessfully = false; int iterationCount = 1; System.Threading.Thread.Sleep(2000); while (loggedInSuccessfully == false && iterationCount <= 5) { try { IWebElement subscriptionContent = driver.FindElement(By.Id("subscriptions-list")); IWebElement firstSubscriptionLink = subscriptionContent.FindElement(By.TagName("a")); firstSubscriptionLink.Click(); IWebElement charged = driver.FindElement(By.ClassName("subscription-estimated-cost")); retVal = charged.Text; loggedInSuccessfully = true; NetUtil.AddEventLogEntry("BillProvider", "Application", "Account balance populated - " + userName + "."); System.Threading.Thread.Sleep(2000); try { IWebElement logoutBtn = driver.FindElement(By.Id("header-sign-in")); logoutBtn.Click(); } catch { NetUtil.AddEventLogEntry("BillProvider", "Application", "Unable to click logout button - " + userName + "."); } } catch { //Exception here means login button is still processing, subscription info not loaded. Try clicking login button again. loginBtn.Click(); System.Threading.Thread.Sleep(2000); IWebElement subscriptionContent = driver.FindElement(By.Id("subscriptions-list")); IWebElement firstSubscriptionLink = subscriptionContent.FindElement(By.TagName("a")); firstSubscriptionLink.Click(); IWebElement charged = driver.FindElement(By.ClassName("subscription-estimated-cost")); retVal = charged.Text; loggedInSuccessfully = true; NetUtil.AddEventLogEntry("BillProvider", "Application", "Account balance populated - " + userName + "."); try { IWebElement logoutBtn = driver.FindElement(By.Id("header-sign-in")); logoutBtn.Click(); } catch { NetUtil.AddEventLogEntry("BillProvider", "Application", "Unable to click logout button - " + userName + "."); } } iterationCount++; } if (!loggedInSuccessfully) { retVal = "Error loading subscription information."; NetUtil.AddEventLogEntry("BillProvider", "Application", "Error loading subscription balance after retry - " + userName + "."); } } } driver.Quit(); } } catch(Exception ex) { NetUtil.AddEventLogEntry("BillProvider", "Application", "Unable start IE driver: " + ex.Message); } return retVal; }
public void Softuni_OpenSoftUniWebsite_ShouldPassTest() { using (IWebDriver wdriver = new InternetExplorerDriver()) { wdriver.Navigate().GoToUrl("https://softuni.bg/trainings/1175/High-Quality-Code-July-2015"); wdriver.FindElement(By.TagName("body")).Click(); string actualLinkText = wdriver.FindElement(By.LinkText("Предишни инстанции на курса")).Text; wdriver.Quit(); } }