0

I'm new to using Selenium and ChromeDriver in C#. I'm trying to click a button element that disappears after clicking it, so I'm getting a StaleElementReferenceException.

IWebElement LoadMoreButton = Driver.FindElementsByTagName("button");
LoadMoreButton.Click();

I'm trying to catch this exception. I can't however, since it's thrown by chromedriver.exe itself and not by my program!! So doing a try-catch won't do anything.

Any ideas? On the other hand, what would be the best approach for clicking a button that will be gone from the DOM?

  • I don't think that there is a way to catch system warning - error using a web automation framework. – dpapadopoulos May 05 '20 at 07:53
  • @dpapadopoulos perhaps I should switch to another webdriver? or I'm doing something wrong... [every solution I find](https://stackoverflow.com/questions/32121089/staleelementreferenceexception-occurs-when-clicking-on-the-buttons-of-a-changed) for what I'm trying to do include catching this exception, however I can't do this –  May 05 '20 at 08:01
  • This is something different. This is an internal error so Selenium can catch it. But the system pop-ups (even if it's Win or Linux) cannot be caught. – dpapadopoulos May 05 '20 at 08:07
  • @dpapadopoulos Right. So how can I make the exception to be thrown inside my program instead of the chromedriver pop-up, so I can catch it? Could I make chromedriver to stop showing these pop-ups as a workaround? I'm totally clueless right now as to what to do. I just want to click a button that disappears after doing so, but I haven't figured out how to catch the stale reference exception... –  May 05 '20 at 08:13
  • I would say that this issue is related to some kind of version - configuration issue. You cannot prevent chrome from showing system pop-ups (only if you disable package but is for sure not recommended since this package is doing many useful actions for you). Most of the times, system pop-ups for chromedriver means that configuration between Selenium webdriver - Chrome - Chromedriver is not properly integrated. – dpapadopoulos May 05 '20 at 08:21

0 Answers0