1

Error message "Element should have been "select" but was "input""is shown when i select the value form drop down box. I have tried with selectByValue() amd selectByIndex().

HTML:

<div class="rcbScroll rcbWidth" style="width: 100%; overflow: auto; height: 40px;">
<ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;">
<li class="rcbItem">TIN</li>
<li class="rcbHovered">SSN</li>
</ul>
</div>

java code is:

Select select=new Select(driver.findElement(By.xpath(OR.getProperty("SSN"))));
select.selectByValue("SSN");
undetected Selenium
194k44 gold badges304 silver badges387 bronze badges
asked Oct 22, 2013 at 10:20
4
  • The above code will only work with <select> tag. I cannot find any <select> tag in the above code ? Commented Oct 22, 2013 at 10:36
  • i have tried with selectByValue() but nothing :( Commented Oct 22, 2013 at 10:42
  • The error is pretty self-explanatory. You are attempting to use the Select class to manipulate a ul element (unordered list). This isn't possible merely because the Select class was created and is used for select (i.e dropdowns) elements only. I fear you are using a web application that styles the list to make it look like a dropdown, thus giving the illusion it is -> but it is clear this is not an ordinary dropdown. Commented Oct 22, 2013 at 18:18
  • you can refer this for more info on this topic Commented Oct 23, 2013 at 5:47

4 Answers 4

1

You can apply select to select value from drop down, there is an li element there and you try to implement using select thats why it thrown the exception

answered Sep 22, 2017 at 6:27
Sign up to request clarification or add additional context in comments.

Comments

0

Yo can Select element by following method

driver.findElement(By.xpath(OR.getProperty("SSN")).click();

In Next line select desired drop down in following way :

driver.findElement(By.xpath("//li[text() = 'SSN']")).click();
iamsankalp89
4,7592 gold badges17 silver badges36 bronze badges
answered Sep 22, 2017 at 6:06

Comments

0

This error message...

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

...implies that you have tried to select the value through an instance of Select object where as the desired element was not a part of any <select> parent tag.

As per the HTML you have shared to click on the option with text as SSN you can use the following code block :

driver.findElement(By.xpath("//div[@class='rcbScroll rcbWidth']")).click();
driver.findElement(By.xpath("//div[@class='rcbScroll rcbWidth']/ul//li[@class='rcbHovered' and contains(.,'SSN')]")).click();
answered Apr 25, 2018 at 12:43

Comments

0

Select by will not work for you cuz you need select tag with options tags as sub tags for it. Bellow html code is the correct format you need for using Selenium Select.

<select some-label-name="display label" name="some name" id="some id" title="some title" class="class name">
<option value="0">display label</option>
<option value="1" selected="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

To solve your problem you need to click on the dropdown list to open options then click on the option you need.

answered May 26, 2018 at 13:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.