An extension method might be a better solution here. It would return true
if the element was clicked, and return false
if the element was not interactable.
public static class WebElementExtensions
{
public static void TryClick(this IWebElement element)
{
try
{
element.Click();
return true;
}
catch (ElementNotInteractableException)
{
return false;
}
}
}
Then it is just a simple test:
if (button.TryClick())
{
// Button was clicked successfully
}
else
{
// Button is not interactable
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…