Element should have been "select" but was "span"

7,441 views
Skip to first unread message

sandeep Polepalli

unread,
May 13, 2016, 7:48:51 AM5/13/16
to Selenium Users
Hi ,
Can anyone help me asap

Iam a beginer in selenium iam getting the below error with the below code.

Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span.

Below not selecting drop down code:-

//1st action on drop down
{
 WebElement dd1=driver.findElement(By.xpath(".//*[@id='dcf-fieldset-row-6']/td[2]/span[1]/span[2]/span/span/span[2]/span"));

 dd1.click();
//clicks drop down
 Thread.sleep(3000);
2nd action on same 1st drop down(Here we need to select the option)
 WebElement dd2=driver.findElement(By.xpath(".//*[@id='dcf-fieldset-row-6']/td[2]/span[1]/span[2]/span/span/span[1]"));
 Select s=new Select(dd2);(In this step iam getting stopped(error))
 Thread.sleep(3000);
 
 s.selectByValue("4");
}
Even iam pasting HTML code for the below .

1st xpath below:- .//*[@id='dcf-fieldset-row-6']/td[2]/span[1]/span[2]/span/span/span[2]/span

<tr id="dcf-fieldset-row-6" class="dcf-datafieldrow-label-id-37">
<td id="label-Calls" class="dcf-fieldset-label dcf-dynamic-datafield-label dcf-datafield-label-id-37" style="height: 35px;">
<td class="dcf-fieldset-editable-value" colspan="1">
<span>
<span data-bind="visible:isItemNotEditable(), html:formattedValue('Calls')" style="display: none;">
<span data-bind="visible:isItemEditable()">
<span class="k-widget k-dropdown k-header" style="width: 60px;" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="Calls_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="ba578ed5-77a1-4d1f-be72-45e73a3bd234">
<span class="k-dropdown-wrap k-state-default k-state-focused" unselectable="on">
<span class="k-input" unselectable="on">0</span>
</span>
</span>

2nd xpath below:- .//*[@id='dcf-fieldset-row-6']/td[2]/span[1]/span[2]/span/span/span[1]

<td class="dcf-fieldset-editable-value" colspan="1">
<span>
<span data-bind="visible:isItemNotEditable(), html:formattedValue('Calls')" style="display: none;">
<span class="CellHighlight">0</span>
</span>
<span data-bind="visible:isItemEditable()">
<span class="k-widget k-dropdown k-header" style="width: 60px;" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="Calls_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="ba578ed5-77a1-4d1f-be72-45e73a3bd234">
<span class="k-dropdown-wrap k-state-default" unselectable="on">
<span class="k-input" unselectable="on">0</span>
<span class="k-select" unselectable="on">
<span class="k-icon k-i-arrow-s firefinder-match" unselectable="on">select</span>
</span>
</span>

I need help on the above ASAP.
Also i want to learn xpath online can anyone refer me.

Thanks,
Sandeep Polepalli

⇜Krishnan Mahadevan⇝

unread,
May 13, 2016, 8:18:10 AM5/13/16
to Selenium Users
Sandeep,
The exception is pretty clear.

You are trying to use the Select class on a html element whose type is not "select" 

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/66e56572-0f33-4d26-bac7-7809cb1ba0e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rakesh Gajarmal

unread,
Feb 26, 2017, 2:27:18 PM2/26/17
to Selenium Users
Hi,
getting same exception... have you got solution?? for this error....
if yes please provide solution..

Xiang Dong

unread,
Feb 27, 2017, 9:41:00 PM2/27/17
to seleniu...@googlegroups.com

The HTML shows it is actually a span. you can treat is as a span. things may like below:


1. find to box (span) and click it, then some of options (other span?) will be displayed

2. find the expect option (span) and click it


--david




From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Rakesh Gajarmal <gajarma...@gmail.com>
Sent: Sunday, February 26, 2017 1:51 AM
To: Selenium Users
Subject: [selenium-users] Re: Element should have been "select" but was "span"
 
--
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.

anemuday

unread,
Feb 27, 2017, 11:59:58 PM2/27/17
to Selenium Users
Sandeep,

You use select only if the listbox/dropdown box have 'Options'. You cannot use Span element as 'Select'

Here is below sample HTML:
<select name='Foo'>
<option value='One'>1</option>
<option value='Two'>2</option>

<option value='Three'>3</option>

</select>


In the above case you can use Select like:
WebElement ele=driver.findElement(By.name('Foo'));
Select select=new Select(ele);
select.selectByValue("2");


For detailed explanation, watch this video: How to select a value from a Listbox

But you cannot reference a Span which is not select and doesnt have Options.

Thanks,
Uday
Reply all
Reply to author
Forward
0 new messages