Select Element in DropDownList

I am trying to use select so that I can loop through the options in my dropdown list and randomly access them.

WebElement driver = new ChromeDriver()
WebElement element = driver.findElement(By.id(“TreeList”))
Select oSelect = new Select(element)

oSelect.selectByIndex(3)

Error: Cannot cast object 'ChromeDriver: chrome on XP

Hello,

replace

WebElement driver = new ChromeDriver()

with

WebDriver driver = DriverFactory.getWebDriver()

if you want to use WebDriver instance created by KS.