Single Post

Header

Sunday, November 1, 2015

How to display the dropdown list values in Selenium WebDriver

Display the values fromm the dropdown list using Selenium WebDriver:
1.Creare WebElement variable pointing the dropdown list
2.Get List object using above webelement
3.Display them using for through for each loop

import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumForEach {

@Test
public void dropDownList() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.spicejet.com/");
driver.manage().window().maximize();
Thread.sleep(4000);
// Get the Drop Down element and create an object for that.
WebElement button = driver.findElement(By.cssSelector(".flight_status"));
button.click();
Thread.sleep(4000);
// Switch to the framework
driver.switchTo().frame("RSIFramestatus");
WebElement element = driver.findElement(By.name("originStation"));
   List<WebElement> values = element.findElements(By.tagName("Option"));
for(WebElement value:values) {
    System.out.println("city : "+value.getText());
   }
        driver.close();

}
}

Output:
city : Origin airport
city : Agartala (IXA)
city : Ahmedabad (AMD)
city : Amritsar (ATQ)
city : Aurangabad (IXU)
city : Bagdogra (IXB)
city : Belgaum (IXG)
city : Bengaluru (BLR)
city : Chandigarh (IXC)
city : Chennai (MAA)
city : Coimbatore (CJB)
city : Colombo (CMB)
city : Dehradun (DED)
city : Delhi (DEL)
city : Dharamshala (DHM)
city : Dubai (DXB)
city : Goa (GOI)
city : Guangzhou (CAN)
city : Guwahati (GAU)
city : Hubli (HBX)
city : Hyderabad (HYD)
city : Indore (IDR)
city : Jabalpur (JLR)
city : Jaipur (JAI)
city : Jammu (IXJ)
city : Kabul (KBL)
city : Kathmandu (KTM)
city : Khajuraho (HJR)
city : Kochi (COK)
city : Kolkata (CCU)
city : Kozhikode (CCJ)
city : Lucknow (LKO)
city : Madurai (IXM)
city : Male (MLE)
city : Mandalay (MDL)
city : Mangalore (IXE)
city : Mumbai (BOM)
city : Muscat (MCT)
city : Mysore (MYQ)
city : Port Blair (IXZ)
city : Pune (PNQ)
city : Rajahmundry (RJA)
city : Sharjah (SHJ)
city : Srinagar (SXR)
city : Surat (STV)
city : Thiruvananthapuram (TRV)
city : Tirupati (TIR)
city : Tuticorin (TCR)
city : Udaipur (UDR)
city : Varanasi (VNS)
city : Vijayawada (VGA)
city : Vishakhapatnam (VTZ)

No comments:

Post a Comment