org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was

1,735 views
Skip to first unread message

Priyanka

unread,
Sep 18, 2015, 2:06:39 PM9/18/15
to Selenium Users
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"

I am trying to select value from a dropdown with code as below but it is giving me error as above:


Select dropdownloc = new Select(BrowserUtil.driver.findElement(By.className("dropdowBbutton")));
dropdownloc.selectByValue("France");

Krishnan Mahadevan

unread,
Sep 18, 2015, 10:41:58 PM9/18/15
to Selenium Users
Priyanka,

The problem should be evident from the error message. The Select class cannot be used with "input" tags. It will work only "select" tags.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b2c876e1-b88a-44c3-88ec-efe93ddff56e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bhuvant...@gmail.com

unread,
Aug 20, 2018, 10:59:04 AM8/20/18
to Selenium Users
Hi Priyanaka ,

Screenshot_1.png

Myself getting this error , if i initiate this code , Please guide me

kapeesh gupta

unread,
Apr 16, 2020, 2:39:45 AM4/16/20
to Selenium Users
Hi,

I am trying to read the value from the properties file. But, I am getting the same error. Please let me know where I am wrong? My code is mention below.


Config.properties file:

################### Register Page- test Data ##############
name= kapeesh
email= kapeesh1990@****.com
password= neelgiri123
number= 7447794701
exp_Year= 5
exp_month= 6
################### Register Page- object repository ##############
name_id= fname
email_id= email
pass_id= password
mobile= number
drop_year= expYear
drop_month= expMonth
=========================================================
Class File Code:

package SeleniumFirst;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

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.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ReadProperties {
static WebDriver driver;

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

Properties prop= new Properties();
FileInputStream file= new FileInputStream("D:/Selenium-Apr-20/SeleniumSession/src/SeleniumFirst/config.properties");
prop.load(file);

System.out.println(prop.getProperty("name"));
System.out.println(prop.getProperty("age"));
String url= prop.getProperty("URL");
System.out.println(url);

String browserName= prop.getProperty("browser");
System.out.println(browserName);
System.setProperty("webdriver.chrome.driver", "D://Backup/AA-DesktopFiles/Testing_Tutorial/*****************/Drivers/chromedriver/chromedriver.exe");
//driver = new ChromeDriver();

if(browserName.equals("chrome")){
System.setProperty("webdriver.chrome.driver","D:/Backup/AA-DesktopFiles/Testing_Tutorial/************/Drivers/chromedriver/chromedriver.exe");
driver= new ChromeDriver(); //Launch Driver
}
else if(browserName.equals("FF")){
System.setProperty("webdriver.gecko.driver","D:/Backup/AA-DesktopFiles/Testing_Tutorial/***************/Drivers/geckodriver/geckodriver.exe");
driver= new FirefoxDriver(); //Launch Driver
}
driver.get(url);

driver.findElement(By.xpath(prop.getProperty("btn_name_xPath"))).click();
driver.findElement(By.name(prop.getProperty("name_id"))).sendKeys(prop.getProperty("name"));
driver.findElement(By.name(prop.getProperty("email_id"))).sendKeys(prop.getProperty("email"));
driver.findElement(By.name(prop.getProperty("pass_id"))).sendKeys(prop.getProperty("password"));
driver.findElement(By.name(prop.getProperty("mobile"))).sendKeys(prop.getProperty("number"));

Select select = new Select(driver.findElement(By.name(prop.getProperty("drop_year"))));
select.selectByVisibleText("exp_year");
select.selectByValue(prop.getProperty("exp_Year"));
}
}


Error in Console:
Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'ADMIN-PC', ip: '192.168.43.226', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_191'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.Select.<init>(Select.java:48)
at SeleniumFirst.ReadProperties.main(ReadProperties.java:53)


Hanumantha Reddy

unread,
Apr 16, 2020, 2:46:55 AM4/16/20
to Selenium Users

The problem is in the tag, select work only with Select type of tag, 
You need to look into the drop_year property value,

Select select = new Select(driver.findElement(By.name(prop.getProperty("drop_year"))));

Reply all
Reply to author
Forward
0 new messages