0% found this document useful (0 votes)
15 views

Dropdown 1

This Java program uses Selenium to automate interactions with a web page. It launches the Chrome browser and navigates to the Facebook homepage. It then clicks the "Create New Account" button and selects a day from the dropdown menu by value. It prints out the number of options in the dropdown list and iterates through them, printing the text and value of each option using normal and enhanced for loops.

Uploaded by

yuvaraja s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Dropdown 1

This Java program uses Selenium to automate interactions with a web page. It launches the Chrome browser and navigates to the Facebook homepage. It then clicks the "Create New Account" button and selects a day from the dropdown menu by value. It prints out the number of options in the dropdown list and iterates through them, printing the text and value of each option using normal and enhanced for loops.

Uploaded by

yuvaraja s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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