static void Main(string[] args) { // Compile project // Copy "index.html" and "lenna.png" into CSFileUpload.exe directory (bin\Debug\) // Run and enjoy! // создаём объект WebDriver для браузера FireFox var driver = new FirefoxDriver(); // открываем страницу с формой загрузки файла var fileUri = GetUriFromPath(Path.Combine(Environment.CurrentDirectory, "index.html")); driver.Url = fileUri; // находим элемент <input type="file"> var txtFileUpload = driver.FindElement(By.Id("file")); // заполняем элемент путём до загружаемого файла var sourceFile = Path.Combine(Environment.CurrentDirectory, "lenna.png"); txtFileUpload.SendKeys(sourceFile); // находим элемент <input type="submit"> var btnSubmit = driver.FindElement(By.Id("submit")); // нажимаем на элемент (отправляем форму) btnSubmit.Click(); // закрываем браузер driver.Quit(); }
public void WindowProcess_Demo2() { var articleName = "[小北De编程手记] : Lesson 02 - Selenium For C# 之 核心对象"; _output.WriteLine("Step 01 : 启动浏览器并打开Lesson 01 - Selenium For C#"); IWebDriver driver = new FirefoxDriver(); driver.Url = "http://www.cnblogs.com/NorthAlan/p/5155915.html"; _output.WriteLine("Step 02 : 点击链接打开新页面。"); var lnkArticle02 = driver.FindElement(By.LinkText(articleName)); lnkArticle02.Click(); _output.WriteLine("Step 03 : 根据标题获取新页面的句柄。"); var oldWinHandle = driver.CurrentWindowHandle; foreach (var winHandle in driver.WindowHandles) { driver.SwitchTo().Window(winHandle); if (driver.Title.Contains(articleName)) { break; } } _output.WriteLine("Step 04 : 验证新页面标题是否正确。"); var articleTitle = driver.FindElement(By.Id("cb_post_title_url")); Assert.Equal<string>(articleName, articleTitle.Text); _output.WriteLine("Step 05 : 关闭浏览器。"); driver.Quit(); }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); const int idInicio = 0; const int idFim = 1000; int id = idInicio; String url = "http://fcv.matheusacademico.com.br/Aluno/frmAlunoAlteracao.asp?id="; driver.Navigate().GoToUrl(url + id); driver.Manage().Window.Maximize(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\AllStudents1.txt", true)) { while (id < idFim) { driver.Navigate().GoToUrl(url + id); IWebElement nome = driver.FindElement(By.Id("txtNome")); IWebElement email = driver.FindElement(By.Id("txtmail_maior")); if (nome.GetAttribute("value").ToString() != "") file.WriteLine(id.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString()); id++; } } }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); int idInicio = 30000; int idFinal = 22000; int contador = 1; String url = ""; driver.Navigate().GoToUrl(url + idInicio); driver.Manage().Window.Maximize(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"e:\AllStudents.csv", true)) { while (idInicio > idFinal) { driver.Navigate().GoToUrl(url + idInicio); IWebElement nome = driver.FindElement(By.Id("txtNome")); IWebElement email = driver.FindElement(By.Id("txtmail_maior")); if (email.GetAttribute("value").ToString() != "") { Console.WriteLine(contador + " - " + idInicio.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString()); file.WriteLine(contador + ";" + idInicio.ToString() + ";" + email.GetAttribute("value").ToString() +";"+ nome.GetAttribute("value").ToString()); contador++; } idInicio--; } } }
public static bool LoginToSBM(string siteToTest, string sbmUserName, string sbmUserPass) { ///We will open that URL and will be performing test over it ///string siteToTest = "http://stl-alms-tst4/workcenter/tmtrack.dll?shell=swc"; ///SBM credentials /// string sbmUserName = "******"; /// string sbmUserPass = ""; /// Open the site and wait 5 second while the site is loaded IWebDriver drv = new FirefoxDriver(); ///drv.Navigate().GoToUrl("http://stl-qa-oalmt1/workcenter/tmtrack.dll?shell=swc"); drv.Navigate().GoToUrl(siteToTest); System.Threading.Thread.Sleep(5000); ///find login form Username field and send sbmUserName variable content (string) IWebElement sbmLoginUName = drv.FindElement(By.Id("authUID")); sbmLoginUName.Clear(); sbmLoginUName.SendKeys(sbmUserName); IWebElement sbmLoginUPass = drv.FindElement(By.Id("authPWD")); sbmLoginUPass.Clear(); sbmLoginUPass.SendKeys(sbmUserPass); IWebElement sbmLoginBtn = drv.FindElement(By.Id("logonButton")); sbmLoginBtn.Click(); IWebElement foh = drv.FindElement(By.CssSelector("div.cd-more-info:nth-child(1) > p:nth-child(2) > a:nth-child(3)")); Assert.AreEqual("Full online help",foh,true); return true; }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl(@"http://www.weibo.com"); WebDriverWait waitPageOpen = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); IWebElement inpt_username = waitPageOpen.Until<IWebElement>((d) => { return d.FindElement(By.Name("username")); }); waitPageOpen.Until((d) => { return inpt_username.Displayed; }); inpt_username.SendKeys(@"*****@*****.**"); IWebElement inpt_pwd = driver.FindElement(By.Name("password")); inpt_pwd.SendKeys(@"kodakpdc2000"); IWebElement btn_login = driver.FindElement(By.ClassName("W_btn_g")); btn_login.Click(); waitPageOpen.Until((d)=>{return d.Title.StartsWith("我的首页");}); //IList<IWebElement> personInfos = driver.FindElements(By.ClassName("user_atten")); //if (personInfos.Count == 1) //{ personInfos[0].FindElement(By.PartialLinkText("粉丝")).Click(); } IWebElement temp = driver.FindElement(By.PartialLinkText("粉丝")); temp.Click(); Console.Read(); }
// GET: RunSystemAdministrator public ActionResult RunSalesExecutive() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://localhost:4601/"); var emp = _employeeService .Queryable() .Where(x => x.DepartmentRoleId == 10) .FirstOrDefault (); emp.EmployeeLogin = _employeeLoginService .Queryable() .Where(x => x.EmployeeId == emp.EmployeeId) .FirstOrDefault(); IWebElement UserName = driver.FindElement(By.Name("UserName")); IWebElement Password = driver.FindElement(By.Name("Password")); var loginButton = driver.FindElement(By.XPath("/html/body/div/div/div/section/form/button")); UserName.SendKeys(emp.EmployeeLogin.UserName); Password.SendKeys(emp.EmployeeLogin.Password); loginButton.Click(); Timer timer = new Timer(1000); timer.Start(); timer.Stop(); return View(); }
public void Attack1_Protected() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInput.aspx"); IWebElement query = driver.FindElement(By.Name("fullName")); query.SendKeys("a','2.1'); update students * set gpa = 4.0; --"); query = driver.FindElement(By.Name("GPA")); query.SendKeys("3"); query = driver.FindElement(By.Name("button")); query.Click(); System.Threading.Thread.Sleep(5000); List<LU.ENGI3675.Proj04.App_Code.Students> students = LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read(); bool allfour = true; foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students) { if (temp.GPA < 4.0) allfour = false; Debug.Write((string)temp.Name); Debug.Write(" "); Debug.WriteLine((double)temp.GPA); } Assert.IsFalse(allfour); //if they aren't all 4.0 gpa, then protected against SQL injection driver.Quit(); }
public void Attack2_NonProtected() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInputUNSAFE.aspx"); IWebElement query = driver.FindElement(By.Name("fullNameUS")); query.SendKeys("a','2.1'); update students * set gpa = 4.0; --"); query = driver.FindElement(By.Name("GPAUS")); query.SendKeys("0"); query = driver.FindElement(By.Name("button")); query.Click(); System.Threading.Thread.Sleep(1000); List<LU.ENGI3675.Proj04.App_Code.Students> students = LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read(); foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students) { Assert.IsTrue((double)temp.GPA == 4); //if any of them aren't 4.0, injection failed Debug.Write((string)temp.Name); Debug.Write(" "); Debug.WriteLine((double)temp.GPA); } driver.Quit(); }
public void TestMensagemAlertaNenhumSelecionado() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl(SITE_URL); driver.FindElement(By.Id("btnSolucionar")).Click(); Assert.IsTrue(driver.FindElement(By.Id("divErrorMessage")).Displayed); driver.Quit(); }
public void CreateBugTest() { IWebDriver driver = new FirefoxDriver(); string baseURL = "http://ifdefined.com/btnet/bugs.aspx"; StringBuilder verificationErrors = new StringBuilder(); driver.Navigate().GoToUrl(baseURL); try { Assert.AreEqual("BugTracker.NET - bugs", driver.Title); } catch (Exception e) { verificationErrors.Append(e.Message); } driver.FindElement(By.XPath("//div[contains(@class, 'align')]/table/tbody/tr/td/a")).Click(); try { Assert.AreEqual("BugTracker.NET - Create Bug", driver.Title); } catch (Exception e) { verificationErrors.Append(e.Message); } try { Assert.AreEqual("Project:", driver.FindElement(By.XPath("//span[conatins(@id, 'project_label')]")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } // ERROR: Caught exception [ReferenceError: selectLocator is not defined] driver.FindElement(By.CssSelector("option[value=\"3\"]")).Click(); try { Assert.AreEqual("[no project] DemoProject HasCustomFieldsProject HasDifferentPermissionsProject", driver.FindElement(By.Id("project")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } try { Assert.AreEqual("Project-specific", driver.FindElement(By.Id("label_pcd1")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } driver.Quit(); }
public void MagentoIncorrectUser() { IWebDriver driver = new FirefoxDriver(); string baseURL = "http://demo.nostresscommerce.cz/"; StringBuilder verificationErrors = new StringBuilder(); driver.Navigate().GoToUrl(baseURL); driver.FindElement(By.XPath("//*[contains(@class, 'links')]/li/a")).Click(); driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).Clear(); driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).SendKeys("*****@*****.**"); driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).Clear(); driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).SendKeys("123456"); driver.FindElement(By.Id("send2")).Click(); for (int second = 0; ; second++) { if (second >= 60) Assert.Fail("timeout"); try { if ("Login or Create an Account" == driver.FindElement(By.CssSelector("h1")).Text) break; } catch (Exception) { } Thread.Sleep(1000); } try { Assert.AreEqual("Login or Create an Account", driver.FindElement(By.CssSelector("h1")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } for (int second = 0; ; second++) { if (second >= 60) Assert.Fail("timeout"); try { if ("Invalid login or password." == driver.FindElement(By.CssSelector("li > span")).Text) break; } catch (Exception) { } Thread.Sleep(1000); } try { Assert.AreEqual("Invalid login or password.", driver.FindElement(By.CssSelector("li > span")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } driver.Quit(); }
public void Add_Tweet_FindNewTweetInNewsfeed() { firefox = new FirefoxDriver(); firefox.Navigate().GoToUrl("http://*****:*****@mail.com"); //firefox.FindElement(By.Id("inputPassword")).SendKeys("123"); //firefox.FindElement(By.Id("submit")).Click(); //firefox.FindElement(By.Id("login")).Click(); //log in page firefox.FindElement(By.Id("inputEmail")).SendKeys("*****@*****.**"); firefox.FindElement(By.Id("inputPassword")).SendKeys("123"); firefox.FindElement(By.Id("login")).Click(); firefox.FindElement(By.Name("Body")).Click(); firefox.FindElement(By.Name("Body")).SendKeys("test Tweet"); firefox.FindElement(By.Id("tweetbutton")).Click(); firefox.FindElement(By.Id("home")).Click(); string tweetMessage = firefox.FindElement(By.TagName("h5")).Text; Assert.IsTrue(tweetMessage == "test Tweet"); }
public void Should_display_asterisk_against_missing_user_name() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://localhost:1392/"); driver.FindElement(By.Id("login_LoginButton")).Click(); var missing = driver.FindElement(By.Id("login_UserNameRequired")); Assert.IsTrue(missing.Displayed); driver.Quit(); }
public void HackathonTest() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://testerzy.pl"); driver.FindElement(By.Id("mod-search-searchword")).SendKeys("hackathon dev qa"); driver.FindElement(By.ClassName("button")).Click(); Assert.True(driver.FindElement(By.ClassName("result-title")).Text.Contains("Hackathon")); driver.Quit(); }
static void Main() { using (var driver = new OpenQA.Selenium.Firefox.FirefoxDriver(AppDomain.CurrentDomain.BaseDirectory)) { 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); } }
public void Test2() { var driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://tourism.51book.com/adminLogin.htm"); driver.FindElement(By.Id("userName")).SendKeys("ZLBGYCS"); driver.FindElement(By.Id("password")).SendKeys("123456"); driver.FindElement(By.Id("submit")).Submit(); driver.FindElement(By.XPath("/html/body/table/tbody/tr/td[1]/div/a[1]")).Click(); driver.FindElement(By.Id("nextSteps")).Click(); driver.SwitchTo().DefaultContent(); driver.SwitchTo().Frame(""); }
public void TestMensagemSomenteLocalSelecionado() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl(SITE_URL); IWebElement lbPlaces = driver.FindElement(By.Id("lbPlaces")); new SelectElement(lbPlaces).Options[0].Click(); driver.FindElement(By.Id("btnSolucionar")).Click(); Assert.IsTrue(driver.FindElement(By.Id("divErrorMessage")).Displayed); driver.Quit(); }
public void XpathTest() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.thetestroom.com/webapp"); // locate the contact link using xpath and click on it driver.FindElement(By.XPath("//a[contains(@id, 'contact_link')]")).Click(); // Now we are on the "Contact" page // locate the name input on "Contact" page using xpath and enter text into it driver.FindElement(By.XPath("//input[contains(@name, 'name_field')]")).SendKeys("test name"); driver.Close(); }
public void MainPage_CanSearchForDinners_ButNeverFindsAnyInKY() { using (IWebDriver driver = new FirefoxDriver()) { driver.Navigate().GoToUrl("http://www.nerddinner.com"); var input = driver.FindElement(By.Id("Location")); input.SendKeys("40056"); var search = driver.FindElement(By.Id("search")); search.Click(); var results = driver.FindElements(By.ClassName("dinnerItem")); // at this point, i don't know what to do, as there's never any search results. Assert.AreEqual(0, results.Count, "No dinners should be found.. omg, if this works, then its worth it to change the test"); } }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://bing.com/"); driver.Manage().Window.Maximize(); IWebElement sString = driver.FindElement(By.Id("sb_form_q")); sString.SendKeys("Hello world"); IWebElement sSubmit = driver.FindElement(By.Id("sb_form_go")); sSubmit.Click(); driver.Close(); }
public void EampleOne() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://order.papajohns.com/storelocator/page.html"); var streetAddress = driver.FindElement(By.Id("streetAddress")); streetAddress.SendKeys("3800 Commerce"); var zip = driver.FindElement(By.Id("zip")); zip.SendKeys("75226"); var searchButton = driver.FindElement(By.Id("mainSearchBtn")); searchButton.Click(); var title = driver.Title; // driver.Quit(); }
private static void DriverTest() { var driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.google.com/"); // Find the text input element by its name var query = driver.FindElement(By.Name("q")); // Enter something to search for query.SendKeys("Cheese"); // Now submit the form. WebDriver will find the form for us from the element query.Submit(); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds var wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(10)); wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); // Should see: "Cheese - Google Search" System.Console.WriteLine("Page title is: " + driver.Title); //Close the browser driver.Quit(); }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.integrationqa.com/"); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); IWebElement menu = driver.FindElement(By.Id("hs_menu_wrapper_module_13970568219884")); Actions builder = new Actions(driver); builder.MoveToElement(menu).Build().Perform(); IList<IWebElement> menuItemsList = menu.FindElements(By.ClassName("hs-menu-item")); String[] menuItems = new String[menuItemsList.Count]; int i = 0; foreach (IWebElement menuItem in menuItemsList) { menuItems[i++] = menuItem.Text; } //Arrange all the list items in alphabetical order IEnumerable<String> orderedMenuList = menuItems.OrderBy(lv_menu => lv_menu).ToList(); //Display the ordered list foreach (var menuItem in orderedMenuList) { if (menuItem.Length > 0) Console.WriteLine(menuItem); } Console.ReadKey(); }
static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.seleniummaster.com/"); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); IWebElement menu = driver.FindElement(By.Id("menubar")); Actions builder = new Actions(driver); builder.MoveToElement(menu).Build().Perform(); IList<IWebElement> menuItemsList = menu.FindElements(By.Id("menu")); char[] delim = { '\r', '\n' }; String[] menuList = menuItemsList[0].Text.Split(delim); //Query to orderby all the list items IEnumerable<string> orderedMenuList = menuList.OrderBy(lv_menu => lv_menu).ToList(); //Display the ordered list foreach (string menuItem in orderedMenuList) { if (menuItem.Length > 0) Console.WriteLine(menuItem); } Console.ReadKey(); }
public void SimpleNavigationTest() { // Create a new instance of the Firefox driver. // Notice that the remainder of the code relies on the interface, // not the implementation. // Further note that other drivers (InternetExplorerDriver, // ChromeDriver, etc.) will require further configuration // before this example will work. See the wiki pages for the // individual drivers at http://code.google.com/p/selenium/wiki // for further information. IWebDriver driver = new FirefoxDriver(); //Notice navigation is slightly different than the Java version //This is because 'get' is a keyword in C# driver.Navigate().GoToUrl("http://www.google.com/"); // Find the text input element by its name IWebElement query = driver.FindElement(By.Name("q")); // Enter something to search for query.SendKeys("Cheese"); // Now submit the form. WebDriver will find the form for us from the element query.Submit(); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); //Close the browser driver.Quit(); }
public void Should_present_invalid_login_message_when_user_is_not_known() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://localhost:1392/"); var userName= driver.FindElement(By.Id("login_UserName")); userName.Clear(); userName.SendKeys("Admin"); driver.FindElement(By.Id("login_Password")).Clear(); driver.FindElement(By.Id("login_Password")).SendKeys("wrong"); driver.FindElement(By.Id("login_LoginButton")).Click(); Assert.IsTrue(driver.FindElement(By.TagName("body")).Text.Contains("Your login attempt was not successful. Please try again.")); driver.Quit(); }
public void GivenIAmOnTheQAWorksAndClick() { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("site"); IWebElement contact = driver.FindElement(By.LinkText("contact")); contact.Click(); }
public void ThenThenIShouldBeAbleToContactQAWorksWithAndTheInformation(string name, string email, string message) { Properties Homepage = new Properties(); IWebDriver driver = new FirefoxDriver(); IWebElement Name = driver.FindElement(By.Id("ctl00_MainContent_NameBox")); Name.SendKeys(name); IWebElement Email = driver.FindElement(By.Id("ctl00_MainContent_EmailBox")); Email.SendKeys(email); IWebElement Message = driver.FindElement(By.Id("ctl00_MainContent_MessageBox")); Message.SendKeys(message); IWebElement Send = driver.FindElement(By.Id("ctl00$MainContent$SendButton")); Send.Submit(); }
public void Visit_Cnblogs() { IWebDriver driver = new FirefoxDriver(); driver.Url = "http://www.cnblogs.com/NorthAlan"; var lnkAutomation = driver.FindElement(By.XPath(".//div[@id='sidebar_postcategory']/ul/li/a[text()='自动化测试']")); lnkAutomation.Click(); }
public void a_bit_easier_to_read() { var profile = new FirefoxProfile(); var exe = new FirefoxBinary(@"D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); IWebDriver browser = new FirefoxDriver(exe, profile); WebDriverWait wait = new WebDriverWait(browser,TimeSpan.FromSeconds(10)); browser.Navigate().GoToUrl("http://localhost/AJAXDemos/CascadingDropDown/CascadingDropDown.aspx"); //browser.Navigate().GoToUrl("http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx"); wait.Until( ExpectedConditions.ElementExists( By.XPath("id('ctl00_SampleContent_DropDownList1')/option[text()='Acura']"))); var selectionList = browser.FindElement( By.Id("ctl00_SampleContent_DropDownList1")); var optionsList = new SelectElement(selectionList); optionsList.SelectByText("Acura"); wait.Until( ExpectedConditions.ElementExists( By.XPath("id('ctl00_SampleContent_DropDownList2')/option[text()='Integra']"))); selectionList = browser.FindElement( By.Id("ctl00_SampleContent_DropDownList2")); optionsList = new SelectElement(selectionList); optionsList.SelectByText("Integra"); wait.Until( ExpectedConditions.ElementExists( By.XPath("id('ctl00_SampleContent_DropDownList3')/option[text()='Sea Green']"))); selectionList = browser.FindElement( By.Id("ctl00_SampleContent_DropDownList3")); optionsList = new SelectElement(selectionList); optionsList.SelectByText("Sea Green"); wait.Until( ExpectedConditions.ElementExists( By.XPath("//span[@id='ctl00_SampleContent_Label1' and text()='You have chosen a Sea Green Acura Integra. Nice car!']"))); browser.Quit(); }
static void Main(string[] args) { // test with firefox IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(); // test with IE //InternetExplorerOptions options = new InternetExplorerOptions(); //options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; //IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(options); SetupTest(); driver.Navigate().GoToUrl(baseURL + "Account/Login.aspx"); IWebElement inputTextUser = driver.FindElement(By.Id("MainContent_LoginUser_UserName")); inputTextUser.Clear(); driver.FindElement(By.Id("MainContent_LoginUser_UserName")).Clear(); driver.FindElement(By.Id("MainContent_LoginUser_UserName")).SendKeys("usuario"); driver.FindElement(By.Id("MainContent_LoginUser_Password")).Clear(); driver.FindElement(By.Id("MainContent_LoginUser_Password")).SendKeys("123"); driver.FindElement(By.Id("MainContent_LoginUser_LoginButton")).Click(); driver.Navigate().GoToUrl(baseURL + "finanzas/consulta.aspx"); // view combo element IWebElement comboBoxSistema = driver.FindElement(By.Id("MainContent_rcbSistema_Arrow")); //Then click when menu option is visible comboBoxSistema.Click(); System.Threading.Thread.Sleep(500); // container of elements systems combo IWebElement listaDesplegableComboSistemas = driver.FindElement(By.Id("MainContent_rcbSistema_DropDown")); listaDesplegableComboSistemas.FindElement(By.XPath("//li[text()='BOMBEO MECANICO']")).Click(); System.Threading.Thread.Sleep(500); IWebElement comboBoxEquipo = driver.FindElement(By.Id("MainContent_rcbEquipo_Arrow")); //Then click when menu option is visible comboBoxEquipo.Click(); System.Threading.Thread.Sleep(500); // container of elements equipment combo IWebElement listaDesplegableComboEquipos = driver.FindElement(By.Id("MainContent_rcbEquipo_DropDown")); listaDesplegableComboEquipos.FindElement(By.XPath("//li[text()='MINI-V']")).Click(); System.Threading.Thread.Sleep(500); driver.FindElement(By.Id("MainContent_Button1")).Click(); try { Assert.AreEqual("BOMBEO MECANICO_22", driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_LabelSistema\"]")).Text); } catch (AssertionException e) { verificationErrors.Append(e.Message); } // verify coin format $1,234,567.89 usd try { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelInversionInicial\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } try { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoOpMantto\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } try { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } try { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelcostoUnitarioEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } // verify number format 1,234,567.89 try { Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelConsumo\"]")).Text, "((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})?")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } System.Console.WriteLine("errores: " + verificationErrors); System.Threading.Thread.Sleep(20000); driver.Quit(); }