我正在通過 practiceautomation.com 網站練習硒。我在注冊時遇到問題 - 我的選擇器無法找到帶有索引的選項。代碼:Select yearSelector = new Select(driver.findElement(By.id("years"))); yearSelector.selectByIndex(2000);我得到了類似的東西:org.openqa.selenium.NoSuchElementException: Cannot locate option with index: 2000For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.htmlBuild 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);一切正常,通常選擇列表中的日期圖片: 年份 如您所見,年份是可見的。
2 回答
慕慕森
TA貢獻1856條經驗 獲得超17個贊
public void selectByIndex(int index)
上述方法選擇給定索引處的選項。這是通過檢查元素的“索引”屬性來完成的,而不僅僅是通過計數。如果沒有找到匹配的選項元素,則拋出 NoSuchElementException
檢查 html 中的 index 屬性,其值為 2000 它不應該在那里,所以嘗試
selector.selectByIndex(1); // see first visible year is selected or not
添加回答
舉報
0/150
提交
取消
