Error :Cannot instantiate the type Select in selenium webdriver

testng error cannot instantiate class command line
cannot instantiate the type driver in eclipse
could not instantiate class org openqa selenium chrome chromedriver
chromedriver cannot be resolved to a type
the import org.openqa.selenium.support.ui.select cannot be resolved
dynamodbmappingexception could not instantiate class
cannot instantiate the type screen
cannot instantiate the type firefoxdriver

I am testing a website with selenium webdriver. I have imported all the jar files also, but still could not use Select Class in eclipse. It gives me an error: Select class cannot be instantiated. I have also imported org.openqa.selenium.support.ui.Select

Following is my source code

import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Dropdown {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.makemytrip.com");
          WebElementaddress=driver.findElement(By.xpath(".//[@id='to_typeahead1']"));
        Select sc = new Select (address);  // ERROR LINE
        sc.selectByIndex(5);
    }

}

You may try the below. Lets break it down into parts.

Select sc = new Select(driver.findElement(By.xpath("your Xpath match case"))); 
                                 **//this will get the dropdown into sc object**
List<WebElement> we = sc.getOptions();  **//to get the options values into list**
System.out.println(we.size());  **//to print the size in console, this and
                                  previous lines for debug/cross checking**
sc.selectByIndex(5);  **//this will select the 5th index and 6th value(indexing starts from 0)**

Cheers!

Error :Cannot instantiate the type Select in selenium webdriver , Error will go off. Moreover, this element is not a select box. Its an input box. What you can probably try is to click on the element and then try to click on the option you want to select. How to eliminate this error”Cannot instantiate the type Select in selenium webdriver” Try below code. Select sc = new Select(driver.findElement(By.xpath("your

Import org.openqa.selenium.support.ui.Select; package in your project, instead of org.apache.bcel.generic.Select;

Error will go off.

Cannot instantiate the type Select in selenium webdriver, Simply just import the Select import package into your project using: import org. openqa.selenium.support.ui.Select;� Try using the Select import package. You can import it into your project using: import org.openqa.selenium.support.ui.Select;

I see that the Xpath you have provided is not correct. It should be .//*[@id='to_typeahead1']

Moreover, this element is not a select box. Its an input box. What you can probably try is to click on the element and then try to click on the option you want to select.

How to eliminate this error”Cannot instantiate the type Select in , How to eliminate this error”Cannot instantiate the type Select in selenium webdriver”. public class KnowledgeBase{ private WebDriver driver; public KnowledgeBase( WebDriver webDriver ) { driver = webDriver; } //rest of your methods } By refactoring your classes and methods as noted above it will vastly simplify your code which will make the logical errors easier to find if not fix it outright.

I have used the org.openqa.selenium.support.ui.Select package and it worked fine.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class NewClassTest {

    WebDriver driver = new FirefoxDriver();

    @Test
    public void selectOption() {
        driver.get("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select");

        WebElement address = driver.findElement(By.tagName("select"));
        Select ab = new Select(address);
    }

}

Cannot instantiate the type Select in selenium webdriver, the import org.openqa.selenium.support.ui.select cannot be resolved cannot instantiate class error in selenium webdriver testng error cannot instantiate class � The command “chmod + x” exited with code 9009 A project with an output Type of class library cannot be started directly Program does not contain a static ‘Main’ method suitable for an entry point The reference assemblies for framework “.NETFramework,Version=v4.6.1” were not found…

"Cannot instantiate the type Select " need suggestion to correct this , I'm getting this error "Cannot instantiate the type Select" while executing below. test script to read the values WebElement;. org.openqa.selenium.support.ui. Select;. import java.io.*; WebDriver driver = new FirefoxDriver();. This is the java implementation of launching a browser in Selenium. Here, ‘WebDriver’ is an interface and we are creating a reference variable ‘driver’ of type WebDriver, instantiated using ‘FireFoxDriver’ class. For those who are not very proficient in Java, an interface is like a contract that classes implementing it must follow.

Error :Cannot instantiate the type Select in selenium webdriver, Error :Cannot instantiate the type Select in selenium webdriver. I am testing a website with selenium webdriver. I have imported all the jar files also, but still could� How to eliminate this error”Cannot instantiate the type Select in selenium webdriver” Try below code. Select sc = new Select(driver.findElement(By.xpath("your

Cannot Instantiate class error - Selenium WebDriver, It looks like your driver instance is created in one class( lib , (should start with Capital letter BTW)) but you are trying to access it in another class(� Selenium WebDriver does not support automation of Windows based applications. Selenium WebDriver cannot automate image testing, captcha or the otp functionalities. Selenium WebDriver does not have any in-built reporting. Since it is open-source, you will have to rely on community forums for your technical issues.

Comments
  • Do not use phrases like "Help me ASAP" since they are counted as pretty impolite. Noone will help you if you are impolite.
  • You could provide us some HTML code of the select element you are trying to find with @id='to_typeahead1'
  • @Dakkaron , ok i will take care of this in future.
  • @spcial, actually the issue i am getting is , i cannot use Select class in my Program. even after importing the needed Packages.
  • Thanks for reply , but with this also i will get error , as i am getting error while using Select class.
  • Hi @dikshit, please remove import org.apache.bcel.generic.Select; and retry, that should work
  • This is a valid xpath grammer
  • Actually that occurs while pasting here, in my code its with * And I was trying to click and dropdown will open and then i will select the item on index 5. By the way thanks for replying.
  • Welcome to StackOverflow! Good answers address the specific problem.