package test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class CascadingDropDown_visibility {
public WebDriver driver;
public WebDriverWait wait;
@Test
public void cddTest() throws Throwable {
//Explicit wait
wait = new WebDriverWait(driver, 10);
//Drop down 1
WebElement dd1= driver.findElement(By.id("ctl00_SampleContent_DropDownList1"));
//Drop down 2
WebElement dd2= driver.findElement(By.id("ctl00_SampleContent_DropDownList2"));
//Drop down 3
WebElement dd3= driver.findElement(By.id("ctl00_SampleContent_DropDownList3"));
//Select a value from Dropdown 1
Select s1 = new Select(dd1);
s1.selectByVisibleText("Audi");
//Wait until a option loads in second dropdown
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@id=\'ctl00_SampleContent_DropDownList2\']/option[2]")));
Select s2 = new Select(dd2);
s2.selectByVisibleText("A6");
//Wait until a option loads in Third dropdown
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@id=\'ctl00_SampleContent_DropDownList3\']/option[2]")));
Select s3 = new Select(dd3);
s3.selectByVisibleText("Cyan");
Thread.sleep(5000);
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
driver.get("http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx");
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@AfterTest
public void afterTest() {
driver.quit();
}
}