gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:39:30 25 4
gpt4 key购买 nike

我试图在下拉列表中选择一个值,但在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com