簡體   English   中英

無法選擇下拉選項

[英]Can't select the drop-down option

使用選擇方法,我無法選擇下拉菜單

我嘗試使用普通和findelement方法以及索引選擇方法

這是在其他文件中使用輸入值

click(driver,"id",prop.getProperty("state"));
click(driver,"xpath",prop.getProperty("voption"));

和索引選擇方法以及

Select drpCountry = new Select(driver.findElement(By.name("country")));
drpCountry.selectByVisibleText("ANTARCTICA");

預期結果:需要單擊下拉列表

實際結果: “過時的元素引用:元素未附加到頁面文檔中”,它顯示了這樣的錯誤消息

嘗試先找到WebElement ,然后按可見文本進行選擇。

WebElement dropDown = driver.findElement(By.id("state"));
new Select(dropDown).selectByVisibleText("ANTARCTICA");

如果這不起作用,但是您沒有獲得 StaleElementReferenceException請將選擇選項更改為selectByIndex()selectByValue()

如果使StaleElementReferenceException指向與driver.findElement(...)則意味着頁面上的某些內容已更改,因此應引入某種等待機制。 在這種情況下,我建議使用FluentWait找到dropDown

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM