0% found this document useful (0 votes)
27 views2 pages

Select Class

The document discusses using the select class in Selenium to handle dropdown menus. It provides code to find a dropdown element, create a Select object, and select options by text, index, and loop through all available options. It also includes scrolling and clicking a checkbox as additional examples.

Uploaded by

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

Select Class

The document discusses using the select class in Selenium to handle dropdown menus. It provides code to find a dropdown element, create a Select object, and select options by text, index, and loop through all available options. It also includes scrolling and clicking a checkbox as additional examples.

Uploaded by

Akshay Khot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

select class-

To handle the dropdown we can use the select class.

package selenium;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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.support.ui.Select;

public class T1 {

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Admin\\Desktop\\Slenium
Jar\\Chrome_98\\chromedriver.exe");

//Step-1
WebDriver driver =new ChromeDriver();

//step-2
driver.manage().window().maximize();

//step-3
driver.get("https://vctcpune.com/selenium/practice.html");

//Step-4-scrolling

JavascriptExecutor js=(JavascriptExecutor)driver;
Thread.sleep(3000);
js.executeScript("window.scrollBy(0,600)");
Thread.sleep(3000);
js.executeScript("window.scrollBy(0,-600)");
Thread.sleep(3000);
js.executeScript("window.scrollBy(0,600)");
Thread.sleep(3000);
//Step-5 use of select class
WebElement dropdown=driver.findElement(By.id("dropdown-class-
example"));
Select sel=new Select(dropdown);

sel.selectByVisibleText("Option3");
sel.selectByIndex(0);

List<WebElement> option=sel.getOptions();

for (WebElement el1:option) {


System.out.println(el1.getText());
}

WebElement
checkBox=driver.findElement(By.xpath("//input[@id='checkBoxOption1']"));
checkBox.click();
}

You might also like