-1

I have got the error org.openqa.selenium.support.ui.UnexpectedTagNameException Element should have been "select" but was "span". Can you please help?

I have tried this code:

WebElement element = driver.findElement(By.xpath("//span[@id='month']//span[@class='next-select-inner']"));
        Select select = new Select(element);
        select.selectByVisibleText("November");
  • 2
    What you have tried?Where the issue occurs? you would have used the select class where the select tag will not be there in the respective selector. It will help us to make it resolved if you post the HTML Dom code and code you have tried – Mohamed Sulaimaan Sheriff Aug 1 at 12:47
  • I have tried this WebElement element = driver.findElement(By.xpath("//span[@id='month']//span[@class='next-select-inner']")); Select select = new Select(element); select.selectByVisibleText("November"); – karuna Aug 1 at 16:08
2

new Select(element) expects an <SELECT> HTML element e.g. By.xpath("//select") not a <SPAN>. Probaly the implementation of your dropdown is not a HTML Select Tag, but it is a JavaScript custom dropdown. You cannot use the Select helpers.

I think you just need to:

  • Find the dropdown SPAN
  • Click on the dropdown SPAN
  • Wait for an element with text November
  • Click on the found element.
| improve this answer | |

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.