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

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

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()。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5487890.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存