gpt4 book ai didi

java - Selenium/Java - 无法使用索引找到选项

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

我正在通过practiceautomation.com 网站练习selenium。我在注册时遇到问题 - 我的选择器无法通过索引找到选项。

代码:

Select yearSelector = new Select(driver.findElement(By.id("years")));
yearSelector.selectByIndex(2000);

我得到了类似的东西:

org.openqa.selenium.NoSuchElementException: Cannot locate option with index: 2000
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'DESKTOP-NN5LV43', ip: '192.168.0.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.1'
Driver info: driver.version: unknown

很奇怪,因为我也用

Select dateSelector = new Select(driver.findElement(By.id("days")));
dateSelector.selectByIndex(15);

一切正常,通常会选择列表中的日期

图片: Year如您所见,岁月清晰可见。

最佳答案

您尝试按索引2000进行选择,但错误提示没有索引 2000 的选项。也许您想按值进行选择?

Select yearSelector = new Select(driver.findElement(By.id("years")));
yearSelector.selectByValue("2000");

关于java - Selenium/Java - 无法使用索引找到选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52138732/

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