I was using selenium to get data in a table of the website to analytics. I'm must scan and get a table approximately ~1000 rows.
I know the page has Javascript, which automatically updates the DOM. But the table too many rows, so when I scan my code always throw an exception.
I tried with this code:
Boolean breakIt = true;
List<IWebElement> result = new List<IWebElement>();
while (true)
{
breakIt = true;
try
{
IWebElement baseTable = browser.FindElementById("column2");
ReadOnlyCollection<IWebElement> rowsTable = baseTable.FindElements(By.XPath("id('oTable')/table/tbody/tr"));
foreach (IWebElement rows in rowsTable) {
if (rows.FindElements(By.XPath("td")).Count == 10)
result.Add(rows);
}
if (breakIt)
{
break;
}
}
catch (StaleElementReferenceException ser)
{
if (ser.Message.Contains("element is not attached"))
{
browser.Refresh();
browser.WaitForPageToLoad();
browser.GoToFrame(browser.FindElementByXPath("//*[@id='form1']/div[3]/iframe"));
breakIt = false;
}
}
}
It throws an exception like:
Stale element reference: element is not attached to the page document.
Have any idea to resolve my problem? I think using multiple Thread
is the best method.
But I tried with multiple Thread
it also return exceptions.
I think after getting rowsTable.Count
. Divide this /2. And create two thread run this?