public void GetMultipleElementByCSSSelector() { using (IWebDriver driver = new ChromeDriver()) { var testURL = "https://www.seleniumeasy.com/test/bootstrap-dual-list-box-demo.html"; //Arrange driver.Navigate().GoToUrl(testURL); var expectedListItemFirst = "bootstrap-duallist"; var expectedListItemSecond = "Dapibus ac facilisis in"; var expectedListItemThird = "Morbi leo risus"; var expectedListItemForth = "Porta ac consectetur ac"; var expectedListItemFifth = "Vestibulum at eros"; //Act ReadOnlyCollection <IWebElement> listItems = driver.FindElements(By.CssSelector(".list-group > li")); DemoHelper.Pause(1000); var actualListItemFirst = listItems[0].Text; var actualListItemSecond = listItems[1].Text; var actualListItemThird = listItems[2].Text; var actualListItemForth = listItems[3].Text; var actualListItemFifth = listItems[4].Text; //Assert Assert.Equal(expectedListItemFirst, actualListItemFirst); Assert.Equal(expectedListItemSecond, actualListItemSecond); Assert.Equal(expectedListItemThird, actualListItemThird); Assert.Equal(expectedListItemForth, actualListItemForth); Assert.Equal(expectedListItemFifth, actualListItemFifth); } }
public void ManageBrowerWindow() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(HomeUrl); //Act // Maximize the chrome window. driver.Manage().Window.Maximize(); DemoHelper.Pause(); //Minimize the chrome window. driver.Manage().Window.Minimize(); DemoHelper.Pause(); //Set size of chrome window driver.Manage().Window.Size = new System.Drawing.Size(300, 400); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(1, 1); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(100, 100); DemoHelper.Pause(); driver.Manage().Window.Position = new System.Drawing.Point(200, 200); DemoHelper.Pause(); driver.Manage().Window.FullScreen(); //Assert } }
public void ClickOnElementByCSSSelector() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(automationPracticeUrl); var expectedPageTitle = "Order - My Store"; //Act IWebElement shoppingCartLink = driver.FindElement(By.CssSelector("[title='View my shopping cart']")); DemoHelper.Pause(1000); shoppingCartLink.Click(); var actualPageTitle = driver.Title; //Assert Assert.Equal(expectedPageTitle, actualPageTitle); } }
public void ClickOnElementByClass() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(uiTestPlayUrl); string expectedTitle = "UI Test Automation Playground"; //Act // Note that class name should not contain space else this will not work. IWebElement branLink = driver.FindElement(By.ClassName("navbar-brand")); DemoHelper.Pause(1000); branLink.Click(); var actualPageTitle = driver.Title; //Assert Assert.Equal(expectedTitle, actualPageTitle); } }
public void ManageSimpleAlerts() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(AlertURL); //Act driver.FindElement(By.CssSelector("[onclick='jsAlert()']")).Click(); IAlert alertHandle = driver.SwitchTo().Alert(); //Assert // See how we can access to the text of alert box. Assert.Equal("I am a JS Alert", alertHandle.Text); DemoHelper.Pause(5000); // this demonstrates how we cacn accept the alert box. alertHandle.Accept(); } }
public void SubmitForm() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(InputFormURL); //Act // Fill the form driver.FindElement(By.CssSelector("[data-bv-field='first_name']")).SendKeys("Archer"); driver.FindElement(By.CssSelector("[data-bv-field='last_name']")).SendKeys("Malory"); driver.FindElement(By.CssSelector("[data-bv-field='email']")).SendKeys("*****@*****.**"); driver.FindElement(By.CssSelector("[data-bv-field='phone']")).SendKeys("999-999-0007"); driver.FindElement(By.CssSelector("[data-bv-field='address']")).SendKeys("United States"); driver.FindElement(By.CssSelector("[data-bv-field='city']")).SendKeys("Andover"); IWebElement stateListElement = driver.FindElement(By.CssSelector("[data-bv-field='state']")); SelectElement state = new SelectElement(stateListElement); state.SelectByText("Mass"); driver.FindElement(By.CssSelector("[data-bv-field='zip']")).SendKeys("01810"); driver.FindElement(By.CssSelector("[placeholder = 'Website or domain name']")).SendKeys("www.pymonk.com"); driver.FindElement(By.CssSelector("[value = 'yes']")).SendKeys("www.pymonk.com"); driver.FindElement(By.CssSelector("[data-bv-field='comment']")).SendKeys("This is selenium demo"); DemoHelper.Pause(5000); // There is two waye to submit the form. //1. Either use the .Submit() method any element of the form. // Here i have used the first name but we can use any other form field as well to call Submit() method driver.FindElement(By.CssSelector("[data-bv-field='first_name']")).Submit(); DemoHelper.Pause(5000); //2. Find the submit button on the form and call .Click method on that. //These line of codes are commented here but still present to give you a demonstration //driver.FindElement(By.ClassName("glyphicon glyphicon-send")).Click(); //DemoHelper.Pause(5000); //Assert } }
public void EnterMessage() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(TextURL); var expectedText = "Danzer Zone"; //Act // below is the step to fill in the text box. driver.FindElement(By.Id("user-message")).SendKeys("Danzer Zone"); // This step is to click ShowText button and retrieve the text for assertion driver.FindElement(By.CssSelector("[onclick='showInput();']")).Click(); IWebElement messageElement = driver.FindElement(By.Id("display")); DemoHelper.Pause(5000); //Assert Assert.Equal(expectedText, messageElement.Text); } }
public void SelectCheckBox() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(CheckBoxURL); //Act // below is the step to select the Checkbox Button driver.FindElement(By.Id("isAgeSelected")).Click(); driver.FindElements(By.ClassName("cb1-element"))[0].Click(); driver.FindElements(By.ClassName("cb1-element"))[1].Click(); driver.FindElements(By.ClassName("cb1-element"))[2].Click(); driver.FindElements(By.ClassName("cb1-element"))[3].Click(); DemoHelper.Pause(2000); //Assert } }
public void EnterNumbersToGetTotal() { using (IWebDriver driver = new ChromeDriver()) { //Arrange driver.Navigate().GoToUrl(TextURL); var expectedText = "19"; //Act // below is the step to fill in the text box. driver.FindElement(By.Id("sum1")).SendKeys("10"); driver.FindElement(By.Id("sum2")).SendKeys("9"); // This step is to click Get Total button and retrieve the text for assertion driver.FindElement(By.CssSelector("[onclick='return total()']")).Click(); IWebElement sumElement = driver.FindElement(By.Id("displayvalue")); DemoHelper.Pause(5000); //Assert Assert.Equal(expectedText, sumElement.Text); } }