【问题标题】:Getting "Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V" error获取“线程“主”java.lang.NoSuchMethodError 中的异常:org.openqa.selenium.WebElement.setSelected()V”错误
【发布时间】:2020-04-02 02:45:44
【问题描述】:

我正在尝试在下拉列表中选择一个值,但在 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");

错误:

线程“main”中的异常 java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V 在 org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:111) 在 Test.Test1.AppTest.main(AppTest.java:62)

【问题讨论】:

标签: java maven selenium drop-down-menu


【解决方案1】:

试试下面的代码:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    相关资源
    最近更新 更多