I am trying to click an accept terms checkbox while signing up for an account in selenium. My code seems to work, but it only works on some of my customers computers. On those who it doesn't work, it throws a staleelementexception. I have looked online to find a way to handle it such as
bool result = false;
int attempts = 0;
Thread.Sleep(500);
while (attempts < 100)
{
Thread.Sleep(700);
try
{
driver.Navigate().Refresh();
IJavaScriptExecutor javascriptExecutor = (IJavaScriptExecutor)driver;
Actions action = new Actions(driver);
IWebElement db = driver.FindElement(By.XPath("/html/body/div[1]/div/div[2]/form/div[1]/label/span[2]"));
action.MoveToElement(db).Build().Perform();
javascriptExecutor.ExecuteScript("arguments[0].click();", db);
result = true;
break;
}
catch (WebDriverException ee)
{}
attempts++;
}
nextPage(driver, wait);
I have also tried just clicking on it with the driver and clicking with actions, but nothing seems to be working for certain users. I am at the point of not knowing the solution or not knowing what else I can do.
UPDATE 1: While I mentioned this in the comments, I still do receive a stale element, but I seem to of found the cause. When using specific country proxies, it seems that this is thrown. Now the element is still there, but why would the proxies cause this to happen?