java - Selenium/Java - 无法找到带有索引的选项
问题描述
我正在使用 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);
一切正常,通常选择列表中的日期
图片: 年份 如您所见,年份是可见的。
解决方案
您尝试按索引2000进行选择,但错误提示没有索引 2000 的选项。也许您想按值选择?
Select yearSelector = new Select(driver.findElement(By.id("years")));
yearSelector.selectByValue("2000");
推荐阅读
- sql - 对多个参数执行“SELECT TOP 5”的最简单方法是什么?
- php - 正则表达式选择除包含 5 的数字以外的任何内容
- javascript - 如何在按钮单击时获取最近隐藏输入字段的值
- linkedin-api - 将 LinkedIn 迁移到 API v2
- authentication - SPA 中使用刷新令牌和静默身份验证有什么区别?
- material-design - react-admin,折叠菜单时图标消失,只留下标签
- python - 从 python dict 获取某些键
- python - 使用 docker-compose 时看不到 docker 容器中的安装
- excel - Excel VBA 打印到 PDF 每页多张
- javascript - 控制 HTML5 视频中播放的开始位置和持续时间,然后下载该视频的特定持续时间