public void ShouldTestDetailsLink() { var driver = new ChromeDriver(); driver.Navigate().GoToUrl(testUrl); IWebElement element = null; #region TEST CODE element = driver.FindElementByPartialLinkText("Details"); #endregion Assert.IsNotNull(element); Assert.IsTrue(element is IWebElement); Assert.AreEqual(element.GetAttribute("href"), @"https://en.wikipedia.org/wiki/Terry_Pratchett"); driver.Quit(); }
public void ShouldTestListOfBooksLink() { var driver = new ChromeDriver(); driver.Navigate().GoToUrl(testUrl); IWebElement element = null; #region TEST CODE element = driver.FindElementByPartialLinkText("List"); #endregion Assert.IsNotNull(element); Assert.IsTrue(element is IWebElement); Assert.AreEqual(element.GetAttribute("href"), @"https://www.terrypratchettbooks.com/books/"); driver.Quit(); }
public string start() { StringBuilder result = new StringBuilder(); ChromeDriverService ser = ChromeDriverService.CreateDefaultService("drivers"); ser.HideCommandPromptWindow = true; _driver = new ChromeDriver(ser, new ChromeOptions()); WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10)); _driver.Url = _startUrl; _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); //Step.1 Login _driver.FindElementById("loginFacebook").Click(); _driver.FindElementById("email").SendKeys(this._setting.facebook.email); _driver.FindElementById("pass").SendKeys(this._setting.facebook.password); _driver.FindElementById("loginbutton").Click(); //Step.2 Wait _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); foreach (Ticket ticket in this._setting.tickets) { try { _driver.Url = _startUrl; _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); _driver.FindElementByPartialLinkText("立即購票").Click(); //#content > div > div:nth-child(2) > div:nth-child(3) > ul > li:nth-child(1) > a wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("dateSearchGameList"))); _driver.FindElementById("dateSearchGameList").SendKeys(ticket.date); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy( By.CssSelector("tbody > tr:nth-child(1) > td:nth-child(4) > input[type=\"button\"]"))); _driver.FindElementById("gameList") .FindElement(By.CssSelector("tbody > tr:nth-child(1) > td:nth-child(4) > input[type=\"button\"]")).Click(); //Step.4 choose seat _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); var areas = _driver.FindElementsByClassName("area-list"); IWebElement matchSeat = findMatchSeat(areas, ticket.seat); if (matchSeat != null) { matchSeat.Click(); } else { continue; } //Step.4 check ticket ready send! _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); _driver.FindElementByCssSelector("#ticketPriceList >tbody select[name*=TicketForm]").SendKeys(ticket.num.ToString()); _driver.FindElementById("ticketPriceSubmit").Click(); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("submitButton"))); //Step.5 Payment IWebElement matchPayment = findMatchPayment(_driver.FindElementsByCssSelector("#PaymentForm label"), "信用卡"); if (matchPayment != null) { matchPayment.Click(); } else { continue; } //submitButton _driver.FindElementById("cancelOrder").Click(); _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); if (_driver.Url == " http://tixcraft.com/order") { break; } } catch (Exception ex) { result.AppendLine(ex.ToString()); } } return(result.ToString()); }