You are on page 1of 5

DAY08- Lab Assignment

Selenium Assertions and Waits


Practice Form

public void practiceform()


{
IWebDriver driver = new ChromeDriver();
//FirstName
driver.FindElement(By.XPath("//input[@id='firstName']")).SendKeys("kanza");
//Lastname
driver.FindElement(By.Id("lastName")).SendKeys("Ahmed");
//Email
driver.FindElement(By.Id("userEmail")).SendKeys("kanza.ahmed2000@gmail.com");
//Phonenumber
driver.FindElement(By.Id("userNumber")).SendKeys("03352263973");
//radioButtons
Actions action = new Actions(driver);
IWebElement radio = driver.FindElement(By.XPath("//label[@for='gender-radio-2']"));
radio.Click();
action.MoveToElement(radio).Click();
//date
driver.FindElement(By.Id("dateOfBirthInput")).Click();
IWebElement month = driver.FindElement(By.XPath("//*[@id='dateOfBirth']/div[2]/div[2]/div/div/div[2]/
div[1]/div[2]/div[1]/select"));
SelectElement element = new SelectElement(month);
//element.SelectByIndex(0);
//element.SelectByText("Feb");
element.SelectByValue("1");
Thread.Sleep(5000);
IWebElement year = driver.FindElement(By.XPath("//*[@id=\"dateOfBirth\"]/div[2]/div[2]/div/div/div[2]/
div[1]/div[2]/div[2]/select"));
SelectElement YearElement = new SelectElement(year);
YearElement.SelectByIndex(4);
driver.FindElement(By.XPath("//*[@id=\"dateOfBirth\"]/div[2]/div[2]/div/div/div[2]/div[2]/div[3]/div[3]\r\
n")).Click();
//Subject
driver.FindElement(By.XPath("//*[@id=\"subjectsContainer\"]/div/div[1]")).Click();
driver.FindElement(By.Id("subjectsInput")).SendKeys("E");
driver.FindElement(By.XPath("//*[@id=\"react-select-2-option-2\"]")).Click();
driver.FindElement(By.XPath("/html/body/div[2]/div/div/div[2]/div[2]/div[2]/form/div[7]/div[2]/div[1]/
label/text()")).Click();
//ImageUpload
driver.FindElement(By.XPath("//input[@id='uploadPicture']")).SendKeys("C:\\Users\\Kanza\\OneDrive\\
Desktop\\LABS\\SeleniumText.txt");
driver.FindElement(By.XPath("//*[@id=\"state\"]/div/div[1]/div[1]")).Click();
//CurrentAdress
driver.FindElement(By.XPath("//textarea[@id='currentAddress']")).SendKeys("Johar");
// State
IWebElement state = driver.FindElement(By.XPath("//input[@id='react-select-3-input']"));
state.SendKeys("NCR");
state.SendKeys(Keys.Enter);
//city
IWebElement city = driver.FindElement(By.XPath("//*[@id=\"react-select-4-input\"]"));
city.SendKeys("Delhi");
city.SendKeys(Keys.Enter);
//buttonsubmit
driver.FindElement(By.Id("submit")).Click();
Thread.Sleep(2000);
Thread.Sleep(2000);
//#currentAddress Css selector
//textarea[@id='currentAddress'] Xpath
driver.Dispose();
}
}

CheckBox
[TestMethod]
public void Checkbox()
{

IWebElement checkbox = driver.FindElement(By.XPath("//span[contains(text(), 'Home')]"));


if (!checkbox.Selected)
{
checkbox.Click();
}

}
Text Box
public void Textbox()
{
driver.FindElement(By.Id("userName")).SendKeys("admin");
driver.FindElement(By.Id("userEmail")).SendKeys("xyz@gmail.com");
driver.FindElement(By.Id("currentAddress")).SendKeys("Johar");
driver.FindElement(By.Id("permanentAddress")).SendKeys("Johar karachi ");
driver.FindElement(By.Id("submit")).Click();
Thread.Sleep(3000);}
Radio Button

public void RadioButton()


{
IWebDriver driver = new ChromeDriver();
driver.Url = "https://demoqa.com/radio-button";
Actions action = new Actions((IWebDriver)driver);
IWebElement radio = driver.FindElement(By.XPath("//label[@for='impressiveRadio']"));
radio.Click();
action.MoveToElement(radio).Click();}}
Select Menu

[TestMethod]
public void SelectMenu()
{

// Create a new instance of the ChromeDriver


IWebDriver driver = new ChromeDriver();

// Navigate to the webpage with the dropdown element


driver.Navigate().GoToUrl("https://demoqa.com/select-menu");
IWebElement dropdown = driver.FindElement(By.XPath("//*[@id=\"withOptGroup\"]/div/div[1]"));
dropdown.Click();
driver.FindElement(By.XPath("//div[@id='react-select-2-option-0-0']")).Click();
IWebElement One = driver.FindElement(By.XPath("//*[@id=\"selectOne\"]/div[1]/div[1]"));
One.Click();

IWebElement driverc = driver.FindElement(By.XPath("//div[@id='react-select-3-option-0-0']"));


driverc.Click();

driver.FindElement(By.Id("react-select-7-option-0")).Click(); driverc.SendKeys(Keys.Enter);

IWebElement dropdowncolor =
driver.FindElement(By.XPath("//div[@id='selectMenuContainer']//div[@class='row']//
div[contains(@class,'css-1hwfws3')]"));
dropdowncolor.Click();
driver.FindElement(By.XPath("//*[@id=\"react-select-7-option-2\"]")).Click();
driver.FindElement(By.XPath("//*[@id=\"cars\"]/option[1]")).Click();

You might also like