How to eliminate this error”Cannot instantiate the type Select in selenium webdriver”

0 votes
I was writing a code for my website for testing purpose.I added/imported all the jar files also, but still could not use Select Class in eclipse.

It throws an error: Select class cannot be instantiated.

Below is  my 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); } }
May 18, 2018 in Selenium by rajteja
4,449 views

1 answer to this question.

0 votes

Try below code.

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)**

answered May 18, 2018 by Samarpit
• 5,890 points

Related Questions In Selenium

0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 13, 2019 in Selenium by Surya
• 970 points
1,876 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
13,580 views
0 votes
1 answer

How to choose the correct iframe in Selenium WebDriver?

When I checked the website you've mentioned, ...READ MORE

answered Apr 29, 2018 in Selenium by king_kenny
• 3,710 points
651 views
0 votes
0 answers

How to get the text from the HTML5 input error message in Selenium?

On giving invalid data in the email ...READ MORE

Mar 11, 2019 in Selenium by Vaishnavi
• 1,180 points
709 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,813 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,794 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,762 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,129 views
+1 vote
1 answer

How to handle notifications in Python with Selenium (Chrome WebDriver)

Below will help you: You can disable the ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
6,760 views
0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
9,932 views