【发布时间】:2020-05-29 00:35:13
【问题描述】:
我在 tr 标签上有一个带有 onclick 的 html 表格。这个“点击”将我带到一个新的网页,然后我需要返回上一页并继续下一个“tr click”。
到目前为止,我实现了执行第一个onclick,然后当我返回时,Selenium 给我这个错误。
过时的元素引用:元素未附加到页面文档
我的代码
IWebElement table = driver.FindElement(By.Name("pg_table"));
IReadOnlyCollection<IWebElement> rows = table.FindElements(By.XPath(".//tr[@onclick]"));
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
int rowCurrent = 0;
foreach (IWebElement row in rows)
{
js.ExecuteScript($"arguments[{rowCurrent}].click();", row);
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body")));
//retreive data from the new page....
Thread.Sleep(1000);
driver.Navigate().Back();
++rowCurrent;
}
你能帮帮我吗?
提前致谢。
【问题讨论】:
标签: c# selenium navigation back