I'm trying to develop a hack for clicking things with Internet Explorer. My goal is to have one method that I can use that will first try a normal Click()
and if it fails will do a SendKeys("\n")
which seems to be the accepted workaround.
This is my attempt
public void ClickByCssSelectorIeSafe(string cssSelector)
{
try
{
_driver.FindElement(By.CssSelector(cssSelector)).Click();
}
catch (WebDriverException)
{
_driver.FindElement(By.CssSelector(cssSelector)).SendKeys("\n");
}
}
When click succeeds everything works but when I get a WebDriverException in the try clause the FindElement in the catch clause fails even though it succeeded in the try clause. Why?
Another interesting point is that in some cases I can see the Click()
succeed in the browser but it still throws the exception and ends up in the catch clause.
I want this because we're running our tests in Chrome, Firefox and IE and I don't want the IE hack applied everywhere.
The exception message for the failing FindElement in the catch clause looks like this
A first chance exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: The HTTP request to the remote WebDriver server for URL
http://localhost:58124/session/21337088-7630-4709-a902-0a5d1bc7a669/element timed out after 60 seconds.
The exception message for the failing click in the try clause looks like this
A first chance exception of type 'OpenQA.Selenium.WebDriverException'
occurred in WebDriver.dll
Additional information: The HTTP request to the remote WebDriver server for URL
http://localhost:58124/session/21337088-7630-4709-a902-0a5d1bc7a669/element/bcee1534-00e6-4155-b4cc-7171db39f112/click timed out after 60 seconds.