waitForElementClickable($selector, $timeout); // Scroll element into view $this->executeJS("document.querySelector('".$selector."').scrollIntoView({behavior: 'smooth', block: 'center'});"); $this->wait(1); // Small wait after scroll // Try to click $this->click($selector); return; } catch (ElementClickInterceptedException|StaleElementReferenceException $e) { if ($attempt === $maxAttempts) { throw $e; } $this->wait(1); $attempt++; } } } /** * Take debug screenshot on failure */ public function _failed(\Codeception\TestInterface $test, $fail) { $this->makeScreenshot('failed_'.$test->getName()); } }