栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should havebeen “select” but was

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should havebeen “select” but was

这个错误讯息…

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

…意味着您已经使用

Selectclass
与所需的元素进行交互,因为该元素是
<span>

要使用Selenium从下拉列表中选择一个值,例如用户名,您可以使用以下解决方案:

代码块:

      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[@]//li[contains(., 'User Name')]"))).click();
  • Browser Snapshot:

Note:

  • 当页面更改(即DOM)更改时,请始终在尝试方法之前为WebDriverWait诱导。elementToBeClickable()click()
  • 在这个特殊的用例,当你浏览到所需的页面不存在用于需要引起覆盖WebDriverWait的invisibilityOfElementLocated(),然后调用所需click()。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495769.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号