In this post we could learn about to select a option from a dropdown list.
Here is the very basic program to select a option from Blog Archive dropdown available on hello selenium blog homepage:
Here is the very basic program to select a option from Blog Archive dropdown available on hello selenium blog homepage:
Java Source code:
package com.helloselenium.selenium.test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class SelectDropdownOption{ public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://helloselenium.blogspot.com"); Select archiveList = new Select(abhiDriver.findElement(By.id("BlogArchive1_ArchiveMenu"))); archiveList.selectByVisibleText("Apr 2013 (38)"); driver.quit(); } }
Detailed explanation for the above program is as follows:
Above code is package structure for current program file.
Following code is the required packages for Selenium Webdriver.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
Following code is to initialize the Firefox driver.
WebDriver driver = new FirefoxDriver();
driver.get("http://helloselenium.blogspot.com");
You can also use the following code is to open the hello selenium blog in browser.
driver.navigate().to("http://helloselenium.blogspot.com");
Select archiveList = new Select(driver.findElement(By.id("BlogArchive1_ArchiveMenu")));
archiveList.selectByVisibleText("Apr 2013 (38)");
driver.quit();
driver.close();
0 Comments
What would you like to add in my list? I look forward to reading your comments below.