Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

java - org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span" while selecting a dropdown value

Here I am trying to select a value from dropdown using selenium script but I got this error in the console like

"Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"..

public class HomeUserManagement {

public static void main(String args[]) {
    System.setProperty("webdriver.chrome.driver", 
"C:\Users\UMASHANKAR\Documents\selenuim\chromedriver.exe");
    WebDriver driver=new ChromeDriver();
    driver.manage().window().maximize();

//for login
    driver.get("https://ecabportal.azurewebsites.net/dashboard");

driver.findElement(By.name("email")).sendKeys("[email protected]");

driver.findElement(By.name("password")).sendKeys("abc123xyz");
    driver.findElement(By.name("signIn")).click();  


//actual code for selecting a value from dropdown

 driver.get("https://ecabportal.azurewebsites.net/user");
    Select drpdwn=new Select(driver.findElement(By.id("select2-signup-username-container")));
    drpdwn.selectByVisibleText("User Name");
    drpdwn.selectByIndex(0);

there are multiple values in a dropdown I need to select one value in that..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As the error shows you are using <span> tag not Select.

The Select element you are looking for is //*[@id="signup-username"].

Also, you should use WebDriverWait to wait for your locators:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

You should look at ExpectedConditions to wait for...

Hope this helps you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...