enter image description here

Tried this: WebElement searchDropdown = driver.findElementByXPath("//span[@class='selected']"); Select searchFilter = new Select(searchDropdown); searchFilter.selectByVisibleText("Subscription");

But it didn't work.

  • 1. What do you mean "didnt work"? Either there was some exception or the code executed but nothing happened? 2. Is that page public available so that we could test?
    – Alexey R.
    Jun 23, 2018 at 20:56
  • what is the exact error message you are getting? Jun 24, 2018 at 0:27
  • Site url: myfonts.com/home and this is the exception: Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span" Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z' System info: host: 'NOI-NAMITAJ-W10', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131' Driver info: driver.version: unknown at org.openqa.selenium.support.ui.Select.<init>(Select.java:47) at SelectFilter.main(SelectFilter.java:22) Jun 24, 2018 at 7:15

2 Answers 2


You are supposed to get UnexpectedTagNameException as when you try to create an object of Select class on an element, webdriver explicitly checks the tag-name, if it is not select(which is in your case), it throws an UnexpectedTagNameException.

See the implementation code below:

if (null == tagName || !"select".equals(tagName.toLowerCase())) {
      throw new UnexpectedTagNameException("select", tagName);

Now coming to your case, what you can do instead is:

  • Click on All fonts, then click on Subscription.
  • Create a composite click mentioned above using Actions class

Try this below xpath. This will work.

//span[contains(text(), 'All fonts')] 

Moreover from your code, I assume when clicking on the All fonts displays the select dropdown. From your code it seems you haven't clicked on the all fonts. Try clicking on the same Xpath you used and try it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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