我是靠谱客的博主 端庄身影,这篇文章主要介绍java报错类型转换错误_java-类型强制转换为选择时出现错误,现在分享给大家,希望可以做个参考。

>在我的网页中,有多个具有相同属性值的下拉列表

>我将所有这些Webelements放在列表中

>现在使用索引从列表中获取一个WebElement

>在尝试将此WebElement强制类型转换为“选择”时,出现错误:

“java.lang.ClassCastException:

org.openqa.selenium.remote.RemoteWebElement cannot be cast to

org.openqa.selenium.support.ui.Select”

请帮忙!下面是我的代码.

int index;

String sIndex = null;

By element = ORUtils.ORGenerator(pageName,objectName);

//Getting all the webelements with same name in myElement List

java.util.List myElements=WebUtils.driver.findElements(element);

//Get index of element on page

Pattern pIndex=Pattern.compile("(.*)");

Matcher mIndex=pIndex.matcher(objectName);

if(mIndex.find())

{

sIndex=objectName.replaceAll("[a-z]","");

sIndex=sIndex.replaceAll("[A-Z]","");

}

index=Integer.valueOf(sIndex);

index=index-1;

//Getting element from the List using index

WebElement myElement=myElements.get(index);

//Type casting WebElement to Select this is where i get the error**

Select myDropDown=(Select) myElement;

List listOfOptions = myDropDown.getOptions();

//List listOfOptions=myElement.

for(WebElement item : listOfOptions)

{

if(Value.equals((item.getText())))

{

item.click();

Thread.sleep(2000);

break;

}

}

最后

以上就是端庄身影最近收集整理的关于java报错类型转换错误_java-类型强制转换为选择时出现错误的全部内容,更多相关java报错类型转换错误_java-类型强制转换为选择时出现错误内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部