Exception in thread : UnexpectedTagNameException

非 Y 不嫁゛ 提交于 2019-12-12 03:22:22

问题


I am Trying to Locate Dropdown using Select but its giving me error :

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

Tried with ByIndex,ByValue but its not working

Code

Select dropdown = new 
Select(driver.findElement(By.id("ctl00_MainContent_ddlLocale_Input")));
    //dropdown.selectByIndex(2);
     dropdown.selectByValue("Austria: Vienna");

HTML

td class="rcbInputCell rcbInputCellLeft" style="width:100%;">
<input id="ctl00_MainContent_ddlLocale_Input" class="rcbInput ui-widget-    content" type="text" value="Austria: Vienna"     name="ctl00$MainContent$ddlLocale" autocomplete="off"/>

回答1:


As exception clearly saying you are locating the input element but trying to work as select element.

new Select() expect select element as input while you are providing input element as input.

You need to verify your provided id ctl00_MainContent_ddlLocale_Input is the id of input element or select element.

If in your case the ctl00_MainContent_ddlLocale_Input same for both input and select elements, then you need to try usimg cssSelector to specify select element as below :-

Select dropdown = new Select(driver.findElement(By.cssSelector("select#ctl00_MainContent_ddlLocale_Input"))); 

//dropdown.selectByIndex(2);
dropdown.selectByValue("Austria: Vienna");

Hope it helps..:)



来源:https://stackoverflow.com/questions/38499501/exception-in-thread-unexpectedtagnameexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!