org.openqa.selenium.support.ui.UnexpectedTagNameException:元素应该是" select"但是" td"

时间:2014-09-17 06:49:05

标签: selenium selenium-webdriver

所有我对自动化都很陌生 我的问题是我收到了错误

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "td"

当我尝试从下拉列表中选择一个选项时 这是我的酸法代码

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帮助我摆脱这个......

1 个答案:

答案 0 :(得分:1)

错误消息非常具有描述性,当您需要td时(正确地说是这样),您已经给它select

所以这里:

 Select CompanyOptions = new Select(_driver.findElement(By.xpath(".//*[@id='company._idCell']")));

您需要对其进行更改,以便为其提供select

Select CompanyOptions = new Select(_driver.findElement(By.id("inputSelect")));