org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应已被“选择".但是是"td" [英] org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "td"
本文介绍了org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应已被“选择".但是是"td"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有这些我对自动化非常陌生 我的问题是我遇到了错误
hii all i am very new to automation my problem is i am getting an error
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "td"
当我尝试从下拉列表中选择一个选项时 这是我的原始代码
when i am trying to select an option from dropdown list this is my sourch code
public void CompanyFilters_Fn() {
// TODO Auto-generated method stub
_driver.findElement(By.xpath(".//*[@id='company._idCell']")).click();
Select CompanyOptions = new Select(_driver.findElement(By.xpath(".//*[@id='company._idCell']")));
CompanyOptions.deselectAll();
CompanyOptions.selectByIndex(5150);
CompanyOptions.selectByIndex(5003);
}
这是我的html代码
<td id="company._idCell" class="filterValue filterActive filterChanged firepath-matching-node" onclick="showInputElement('pre.myProjectsForm.company._id', this, null, 'auto'); return false;" title="Select to filter by Company">Company: [No Company]</td>
这些是选项
<div id="divSelect" class="inputElement" style="left: -1000px; top: 212px; width: auto; height: 20px;">
<select id="inputSelect" size="5" style="width: auto; visibility: visible;" multiple="" disabled="">
<option value="-1">Any</option>
<option value="0">[No Company]</option>
<option value="5150">123</option>
<option value="5203">AutoCarLoanCompany</option>
<option value="5205">Company_rahul</option>
<option value="5202">CreditCardCompany</option>
<option value="5003">IBM</option>
<option value="5204">June</option>
<option value="5300">other companyyyyy</option>
<option value="5001">qa</option>
<option value="5101">Rahul</option>
</select>
</div>
Plzzz帮助我摆脱困境...
Plzzz help me to get out of this...
推荐答案
该错误消息具有很强的描述性,当期望select
时,您给了它一个td
(正确).
The error message is very descriptive, you've given it a td
when it expects a select
(rightly so).
所以在这里:
Select CompanyOptions = new Select(_driver.findElement(By.xpath(".//*[@id='company._idCell']")));
您需要对此进行更改以使其具有select
:
You need to change this to give it the select
:
Select CompanyOptions = new Select(_driver.findElement(By.id("inputSelect")));
这篇关于org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应已被“选择".但是是"td"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文