0

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 '18 at 20:56
  • what is the exact error message you are getting? – Vishal Aggarwal Jun 24 '18 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: '192.168.99.1', 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) – Namita Joshi Jun 24 '18 at 7:15
1

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
0

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, privacy policy and cookie policy

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