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");
4 Answers 4
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
Comments
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();
Comments
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();
Comments
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.
Comments
Explore related questions
See similar questions with these tags.
Select
class to manipulate aul
element (unordered list). This isn't possible merely because theSelect
class was created and is used forselect
(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.