Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “a”

Open 2 Answers 88 Views
0 2
package practice;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
public class Vistair2 {
    @Test public void seeProducts() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "/Users/dominiclee/Documents/workspace/chromedriver 4");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.vistair.com/");
        driver.manage().window().maximize();
 
        Thread.sleep(10000);
        //Create action builder instance by passing WebDriver instance
        driver.findElement(By.id("hs-eu-confirmation-button")).click();
        Actions builder = new Actions(driver);
        WebElement menuElement = driver.findElement(By.linkText("SOLUTIONS"));
        builder.moveToElement(menuElement).build().perform();
        Thread.sleep(10000);
 
        Select dropDown = new Select(driver.findElement(By.linkText("SOLUTIONS")));
        List < WebElement > e = dropDown.getOptions();
        int itemsCount = e.size();
        System.out.println(itemsCount);
        //driver.close();
 
    }
}

When I run this in Selenium I get the following error: Element should have been "select" but was "a"
I want to find the size of the dropdown menu?

2 Answers

2
2

Select dropDown = new Select(driver.findElement(By.linkText("SOLUTIONS"))); points to <a> tag than <select> tag. Please make appropriate correction in findElement() method call.

answered by (52 points)
edited by
1Comments
commented by (136 points)
Thank you @Das888
1
1

Select dropDown = new Select(driver.findElement(By.linkText("SOLUTIONS")));

In your above statement, you are creating a Select object but the locator (By.linkText("SOLUTIONS")) you have passed inside the constructor is pointing to an anchor tag <a> instead of a Select tag <select>

The locator that you are passing inside the Select constructor should point to the Select tag only. In your case, it is pointing to the anchor tag. That is why it is throwing this error.

Please recheck the locator in DOM first.

answered by (31 points)
1Comments
commented by (136 points)
Thank you @Sarvesh4you. That's well explained.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...