Mahen
Mahen

Reputation: 9

Selenium Java - Error- org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"

I am new to java and selenium . I am trying to learn automation on one of my project website

But I am stuck in one of drop down. Below is HTML for drop-down.

 <td>
<select name="NAV_LOB_FLD.XMFRAMEWORK.XMCONTROL.1" size="1">
<option value="" selected="selected">Select Business Line</option>
<option value="X01">Auto</option>
<option value="J57">Businessowners(ISO)</option>
<option value="X22">Dwelling Fire</option>
<option value="X26">Farmowners</option>
<option value="X24">Homeowners</option>
<option value="X44">Umbrella - Personal Lines</option>
<option value="J34">Watercraft</option>
</select></td>

and My code is

  Select SelectLOB = new Select(driverIE.findElement(By.name("NAV_LOB_FLD.XMFRAMEWORK.XMCONTROL.1")));
  SelectLOB.selectByValue("Auto");

I am not able to figure out why this error is there. There is only one element by this name. I understand it says its of tag input rather than select. But that's not the case .

Please help. Thanks in advance.

Upvotes: 0

Views: 3724

Answers (3)

Mahen
Mahen

Reputation: 9

Thanks @Eugene @Saifur. I tried value X01 and different element techniques( Xpath,css) but it's not working in IE 8 or 11 and this application only support IE

I create HTML file and tried in firefox it's wokring.

Then I tried

WebElement select = driverIE.findElement(By.tagName("select"));
        System.out.println(select);
        List<WebElement> allOptions = select.findElements(By.tagName("option"));
        for (WebElement option : allOptions) {
            System.out.println(String.format("Value is: %s", option.getAttribute("value")));
            option.click();}

It provide me Values I wanted from dropdown.

So i modified my code to

new Select(driverIE.findElement(By.tagName("select"))).selectByVisibleText("Auto");

I know this is not proper solution but a temp workaround. Thanks .

Upvotes: 1

Saifur
Saifur

Reputation: 16201

Wheres @Eugene is right there are multiple other factors which can directly influence this c.lass I had to deal with wait several times and different find element techniques. If @Eugene's answer does not work see my answer here

Upvotes: 0

Eugene
Eugene

Reputation: 1895

You are using

SelectLOB.selectByValue("Auto"); 

However the correct code should be

SelectLOB.selectByValue("X01");

Please see if that fix the problem. It's works on my chrome driver.

Upvotes: 0

Related Questions