import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class DellDropdown {
public static void main(String[] args)
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("http://www.dell.com/");
driver.findElement(By.xpath("//a[@class='ctryName']")).click();
WebElement countryDropdown=driver.findElement(By.xpath("//select[@class='para_small']"));
Select selectElement = new Select(countryDropdown);
selectElement.selectByVisibleText("India");
if(driver.findElement(By.xpath("//a[@class='ctryName' and text()='India']")).getText().equals("India")){
System.out.println("The dropdown is changed to india");
}
WebElement selectedCountryDropdown=driver.findElement(By.xpath("//select[@class='para_small']"));
selectElement = new Select(selectedCountryDropdown);
List<WebElement> options=selectElement.getOptions();
for(int i=0;i<options.size();i++){
WebElement option=options.get(i);
String countryName=option.getText();
boolean selectedValue=option.isSelected();
System.out.print(countryName);
System.out.println(selectedValue);
}
driver.close();
}
}
On selecting country India from the country dropdown in the dell site I am not getting the text from the option tag of the dropdown only the selected status is returned.Kindly let me know how to get the text?