java - 获取 "Exception in thread "main“java.lang.NoSuchMethodError : org. openqa.selenium.WebElement.setSelected()V”错误

标签 java maven selenium drop-down-menu

我试图在下拉列表中选择一个值,但在 maven 中出现 Exception in thread "main"java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected() 错误项目。

代码:

Select dropdown = new Select(driver.findElement(By.xpath("//select[@name=\"ppw-expirationDate_year\"]")));
dropdown.selectByVisibleText("2025");

错误:

Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V at org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:111) at Test.Test1.AppTest.main(AppTest.java:62)

最佳答案

尝试使用以下代码:

Select dropdown = new Select(driver.findElement(By.xpath("//select[@name='ppw-expirationDate_year']")));
dropdown.selectByVisibleText("2025");

您必须确保在单引号中写入属性值,并删除 IDE 默认放置的转义字符。

关于java - 获取 "Exception in thread "main“java.lang.NoSuchMethodError : org. openqa.selenium.WebElement.setSelected()V”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60983479/

相关文章:

java - 打包时包含运行时依赖项的 Maven 方式

java - (Selenium) 如何测试某个文件是否开始下载?

selenium - PHPUnit 和 WebDriver - 如何获取当前 URL?

java - 如何使用 Selenium WebDriver 复制表格?

java - 整洁架构 : Combining Interactors

java - vagrant 对 java/javaee 开发人员有用吗?

java - Maven - 覆盖测试资源文件夹

java - IntelliJ - 包 org.springframework.stereotype 不存在

java - Python Blowfish 加密

java - 如何在 Android 中播放音频文件?