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); } }