线程中的异常:UnexpectedTagNameException [英] Exception in thread : UnexpectedTagNameException

查看:495
本文介绍了线程中的异常:UnexpectedTagNameException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


线程main中的异常org.openqa.selenium .support.ui.UnexpectedTagNameException:元素应该是选择,但是输入

尝试使用ByIndex,ByValue但它不是工作

代码

 选择下拉菜单= new 
选择(driver.findElement(By.id(ctl00_MainContent_ddlLocale_Input)));
//dropdown.selectByIndex(2);
dropdown.selectByValue(Austria:Vienna);

HTML

  td class =rcbInputCell rcbInputCellLeftstyle =width:100%;> 
< input id =ctl00_MainContent_ddlLocale_Inputclass =rcbInput ui-widget-contenttype =textvalue =Austria:Viennaname =ctl00 $ MainContent $ ddlLocaleautocomplete =off/> ;


解决方案

$ c> input 元素,但试图以选择元素。

<$当您提供输入时,选择新选择()期望选择 >元素作为输入。



您需要验证您提供的ID ctl00_MainContent_ddlLocale_Input input 元素或 select 元素。



如果你的情况是 ctl00_MainContent_ddlLocale_Input 对于输入选择元素都是相同的,那么您需要尝试usimg cssSelector 指定选择元素如下: - $ /

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

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

希望它能帮助..:)

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"/>

解决方案

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..:)

这篇关于线程中的异常:UnexpectedTagNameException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆