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
1,090 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,130 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 6 days ago in Selenium by Surya
• 860 points
23 views
0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
5,048 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,590 points
161 views
0 votes
0 answers
0 votes
1 answer

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,050 points
142 views
0 votes
1 answer
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,130 points
531 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
134 views
0 votes
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,130 points
1,559 views
0 votes
1 answer

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

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
2,214 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.