You are on page 1of 3

package test;

import java.util.List;
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.support.ui.Select;

public class Test {

public static void main(String[] args) throws


InterruptedException {

//Launching the Browser


System.setProperty("webdriver.chrome.driver", "C:\\
Users\\Laptop3\\eclipse-workspace\\Test1'\\driver\\
chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://en-gb.facebook.com/");

WebElement btnCreate =
driver.findElement(By.xpath("//a[text()='Create New
Account']"));
btnCreate.click();

Thread.sleep(3000);

WebElement ddnDay =
driver.findElement(By.id("day"));
Select s = new Select(ddnDay);

//s.selectByVisibleText("5");
//s.selectByIndex(2);
s.selectByValue("6");

//To find the count of options in the list


List<WebElement> allOptions = s.getOptions();
System.out.println(allOptions.size());
//Print all the visible text - using normal for
loop
for(int i = 0; i < allOptions.size() ; i++)
{

System.out.println(allOptions.get(i).getText());
// WebElement we = allOptions.get(i);
//individual webelement
// String text = we.getText();
// System.out.println(text);
}

System.out.println("**********");

//Printing all the value - using normal forloop

for(int i = 0 ; i < allOptions.size(); i++)


{

System.out.println(allOptions.get(i).getAttribute("value"));

// WebElement we1 = allOptions.get(i);


// String val = we1.getAttribute("value");
// System.out.println(val);
}

System.out.println("enhanced for loop");

//Printing all the text - using enhanced forloop

for (WebElement x : allOptions) {

System.out.println(x.getText());

System.out.println("************");

//Printing all the value - using enhanced forloop


for (WebElement x : allOptions) {

System.out.println(x.getAttribute("value"));

You might also like