Select option is not working getting following error [Element should have been "select" but was "input"]

1,343 views
Skip to first unread message

Suresh Kumar

unread,
Oct 3, 2019, 9:33:10 AM10/3/19
to Selenium Users
Hi

I want to select the value from the drop down. This is my code.

Select select_OP = new Select(driver.findElement(By.xpath(("//div[@name='currentcontext.OPTypeId']//input[@name='$select.search']"))));
select_OP.selectByValue("Morning OP");

However when i used, i'm the getting this error.

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: 'DESKTOP', ip: '197.178.4.178', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.Select.<init>(Select.java:48)
    at oasys.hms_login.main(login.java:39)



This is html code for the dropdown. Could you please give suggestion for this.

Shanthi Kandasamy

unread,
Oct 3, 2019, 9:42:55 AM10/3/19
to seleniu...@googlegroups.com
Select select_OP = new Select(driver.findElement(By.xpath("//div[@name='currentcontext.OPTypeId']//input[@name='$select.search']")));
select_OP.selectByValue("Morning OP");

try the above one..you had an unnecessary braces which I removed

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a3713bb9-bbe3-407e-99ed-7b3ad9fb929f%40googlegroups.com.

Suresh Kumar

unread,
Oct 3, 2019, 9:54:12 AM10/3/19
to seleniu...@googlegroups.com
Hi Shanthi,

I tried, but it's not selecting the value in drop down. Following error is displayed.

main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/CA7_FnmKzY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CABwD1hvY4gh21wp6-RFNThG1P196RRwzk2cnj8EtcfUsk5%2BPZw%40mail.gmail.com.

thilana Athi

unread,
Oct 3, 2019, 10:03:06 AM10/3/19
to seleniu...@googlegroups.com
The locator that you are passing inside the Select constructor should point to the Select tag only. In your case, it is pointing to the input  tag. That is why it is throwing this error.

Kindly go through the below part of the select class of selenium. You can get to know the reason behind it. 
https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/ui/Select.java

You can follow below alternate way.
1.Click the element on which will display dropdown options
2.Now click on the respective option directly just like clicking any webElement by locating it with relative xpath.

Thanks,
Athithan Raj P


Shanthi Kandasamy

unread,
Oct 3, 2019, 10:21:47 AM10/3/19
to seleniu...@googlegroups.com
input[@name='$select.search']")));

In the above line its expecting select tag as in <select> don't you have select tag in the DOM?


Suresh Kumar

unread,
Oct 3, 2019, 12:41:16 PM10/3/19
to seleniu...@googlegroups.com
Hi Shanthi,

Can you please tell me how to select by using DOM. Screenshot attached.


Thanks.

Auto Generated Inline Image 1

argo triwidodo

unread,
Oct 3, 2019, 6:01:10 PM10/3/19
to Selenium Users
Hello, 

I think that is not standard selection input, 
if it's not standard select input, it will not working if you using new Select() 

you can  try to use default action click (find(By.xpath).click) for click / select the element


Pada Kamis, 03 Oktober 2019 23.41.16 UTC+7, Suresh Kumar menulis:
Hi Shanthi,

Can you please tell me how to select by using DOM. Screenshot attached.


Thanks.

On Thu, Oct 3, 2019, 7:51 PM Shanthi Kandasamy <shanth...@gmail.com> wrote:
input[@name='$select.search']")));

In the above line its expecting select tag as in <select> don't you have select tag in the DOM?


On Thu, Oct 3, 2019 at 7:24 PM Suresh Kumar <suri...@gmail.com> wrote:
Hi Shanthi,

I tried, but it's not selecting the value in drop down. Following error is displayed.

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

On Thu, Oct 3, 2019 at 7:12 PM Shanthi Kandasamy <shanth...@gmail.com> wrote:
Select select_OP = new Select(driver.findElement(By.xpath("//div[@name='currentcontext.OPTypeId']//input[@name='$select.search']")));
select_OP.selectByValue("Morning OP");

try the above one..you had an unnecessary braces which I removed

On Thu, Oct 3, 2019 at 7:03 PM Suresh Kumar <suri...@gmail.com> wrote:
Hi

I want to select the value from the drop down. This is my code.

Select select_OP = new Select(driver.findElement(By.xpath(("//div[@name='currentcontext.OPTypeId']//input[@name='$select.search']"))));
select_OP.selectByValue("Morning OP");

However when i used, i'm the getting this error.

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: 'DESKTOP', ip: '197.178.4.178', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.Select.<init>(Select.java:48)
    at oasys.hms_login.main(login.java:39)



This is html code for the dropdown. Could you please give suggestion for this.

--
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 seleniu...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/CA7_FnmKzY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to seleniu...@googlegroups.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 seleniu...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/CA7_FnmKzY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to seleniu...@googlegroups.com.

Suresh Kumar

unread,
Oct 4, 2019, 12:53:12 AM10/4/19
to seleniu...@googlegroups.com
Hi

OK Thanks, i will use the default click action and see.

Regrads
Sureshkumar

To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d6217e99-8dac-49bf-bc36-c2fb005188a0%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages