您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

org.openqa.selenium.support.ui.UnexpectedTagNameException:在选择下拉值时,元素应为“选择”但为“跨度”

org.openqa.selenium.support.ui.UnexpectedTagNameException:在选择下拉值时,元素应为“选择”但为“跨度”

@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();

UserName

Note:

其他 2022/1/1 18:14:43 有496人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶