我必須點擊頁面上的某個按鈕。但是,當我檢索具有特定類名稱的所有元素時。當我嘗試執行每一個或單擊時,所有檢索到的元素都會拋出一個陳舊的引用異常。我不能雙擊任何一個。它找到了正確的元素,但卻引發了所有這些異常。註釋掉的代碼是我實際嘗試選擇的位置,然後單擊相應的按鈕。我附上了表格的圖片。請注意,每次單擊按鈕或執行按鈕時頁面都會更改。選擇上傳BOM按鈕是您需要特別注意的。 Website硒網絡驅動程序陳舊引用異常
// Switch to correct frame
IWebElement editorFrame = driver.FindElement(By.ClassName("frame-banner"));
driver.SwitchTo().Frame(editorFrame);
var action = new OpenQA.Selenium.Interactions.Actions(driver);
// Select Project File
IList<IWebElement> projectFileButtonList= driver.FindElements(By.ClassName("data-cell"));
foreach (var button in projectFileButtonList)
{
if (button.Text == "BOM_scrub")
{
// Found Project File now select it
action.DoubleClick(button);
action.Perform();
break;
}
}
// Select Upload BOM Button
IList<IWebElement> uploadBomBtn = driver.FindElements(By.ClassName("se-custom-main-button"));
foreach (var element in uploadBomBtn)
{
try
{
action.DoubleClick(element);
action.Perform();
}
catch
{
}
/*
if (element.Text == "Upload BOM")
{
int i = 0;
while (i == 0)
{
try
{
action.DoubleClick(element);
action.Perform();
break;
}
catch
{
}
}
}
*/
}
https://stackoverflow.com/questions/45434381/stale-object-reference-while-navigation-using-selenium/45435158#45435158 –
[PageFactory中的StaleElementReference異常]的可能重複(https://stackoverflow.com/questions/44838538/staleelementreference-exception-in-pagefactory) – DebanjanB