@MosheSlavin的分析和回答是正确的方向。
这个错误讯息…
"Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"
…意味着您已经使用 Select
类与所需 元素进行交互,其中元素为 <span>
.
要使用硒从下拉列表中选择一个值,例如用户名,您可以使用以下解决方案:
driver.get("https://ecabportal.azurewebsites.net/dashboard");
new webdriverwait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.name("email"))).sendKeys("admin@malbork.in");
driver.findElement(By.name("password")).sendKeys("NsSaNj@0205");
driver.findElement(By.name("signIn")).click();
new webdriverwait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[contains(., 'Dashboard')]")));
driver.get("https://ecabportal.azurewebsites.net/user");
new webdriverwait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@id='load']")));
new webdriverwait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span.select2-selection.select2-selection--single>span.select2-selection__rendered"))).click();
new webdriverwait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='select2-results']//li[contains(., 'User Name')]"))).click();
Note: