From 08b23c86748e1e0ac0480f550861980e917a2707 Mon Sep 17 00:00:00 2001 From: Jeanmonod David Date: Wed, 16 Feb 2022 06:50:09 +0100 Subject: [PATCH] Do not randomly click the first matching element --- src/Codeception/Lib/InnerBrowser.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index 5ee79c5..86014a1 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -407,7 +407,10 @@ public function click($link, $context = null): void $anchor = $this->getCrawler()->selectLink($link); } - if (count($anchor) > 0) { + if (count($anchor) > 1) { + throw new TestRuntimeException(count($anchor) . " matching elements found with [$link], try to be more precise about what to click"); + } + if (count($anchor) === 1) { $this->openHrefFromDomNode($anchor->getNode(0)); return; }