我必须点击页面上的某个按钮。但是,当我检索具有特定类名称的所有元素时。当我尝试执行每一个或单击时,所有检索到的元素都会抛出一个陈旧的引用异常。我不能双击任何一个。它找到了正确的元素,但却引发了所有这些异常。注释掉的代码是我实际尝试选择的位置,然后单击相应的按钮。我附上了表格的图片。请注意,每次单击按钮或执行按钮时页面都会更改。选择上传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