Wednesday, 30 December 2015

Select values from drop down one by one (Handling ajax based applications)

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.apache.xalan.trace.SelectionEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Timeouts;
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.BeforeMethod;
import org.testng.annotations.Test;


public class Dropdown_2 {
    WebDriver d1;
    @BeforeMethod
     public void start(){ 
           d1 = new FirefoxDriver();  
         } 
    @Test
    public void Ajaxdropdown(){
               
        d1.get("http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx");
        d1.manage().timeouts().implicitlyWait(40,TimeUnit.MINUTES);
        d1.findElement(By.xpath("//*[@id='sourceTab']")).click();
       
       
        Select s1=new Select(d1.findElement(By.xpath("//*[@id='SelectedBranch']")));
        List<WebElement> droplist=s1.getOptions();
        int count=droplist.size();
        System.out.println(count);
        for (WebElement we:droplist)
        {
            System.out.println("dropdown values are:"+we.getText());
        }
        for(int i=0;i<count;i++)
        {
            WebElement countrydropdown1=d1.findElement(By.xpath("//*[@id='SelectedBranch']"));
            countrydropdown1.click();
            Select s2=new Select(countrydropdown1);
            s2.selectByIndex(i);
            WebElement dBox1= (new    WebDriverWait(d1,50)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='SelectedBranch']")));
            //System.out.println(dBox1);
        }

No comments:

Post a Comment