1

I get the error message when I try to select an item from a menu in a webpage. In the code below, I used the Id of the element. When I tried using the XPath instead of the Id, I got a similar error messsage.

Here is the error in full:

An unhandled exception of type 'OpenQA.Selenium.Support.UI.UnexpectedTagNameException' occurred in WebDriver.Support.dll

Additional information: Element should have been select but was div

And, here is the code:

        //Select "Perday" for Salary Type   
        var salType = driver.FindElement(By.Id("adv-search-mobile"));
        var selectSalType = new SelectElement(salType);

        selectSalType.SelectByText("Per day");

    }
}

HTML:

<select class="adv-search-select sal-type-select" name="salarytype" tabindex="6"> 
    <option value="annum">Per annum</option> 
    <option value="month">Per month</option> 
    <option value="week">Per week</option> 
    <option value="day">Per day</option> 
    <option value="hour">Per hour</option> 
 </select> 
4

The error message is just what it says. The element on your page with ID adv-search-mobile has a <div> tag.

You need to update your locator to get the <select> element (within that <div>. A SelectElement object can only be created from a <select>.

If you need more help, you can post your HTML.

EDIT: If the name of your dropdown is unique, you might try:

var salType = driver.FindElement(By.Name("salarytype"));
  • Is this what you mean, please: select class="adv-search-select sal-type-select" name="salarytype" tabindex="6"> <option value="annum">Per annum</option> <option value="month">Per month</option> <option value="week">Per week</option> <option value="day">Per day</option> <option value="hour">Per hour</option> </select> </div> – OA345 Jun 29 '17 at 7:08
  • See my edit. If that doesn't work, post the <div> tag above the <select> also. – FDM Jun 29 '17 at 7:13
0
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">

        Live Actions<b class="caret"></b></a>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.