diff --git a/src/Browser.php b/src/Browser.php index ac96bdc..9703927 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -260,6 +260,8 @@ final public function attachFile(string $selector, $filename): self } /** + * Click on a button, link or any DOM element. + * * @return static */ final public function click(string $selector): self @@ -268,7 +270,11 @@ final public function click(string $selector): self $this->documentElement()->pressButton($selector); } catch (ElementNotFoundException $e) { // try link - $this->documentElement()->clickLink($selector); + try { + $this->documentElement()->clickLink($selector); + } catch (ElementNotFoundException $e) { + $this->documentElement()->find('css', $selector)->click(); + } } return $this; diff --git a/tests/BrowserTests.php b/tests/BrowserTests.php index 5934e4f..a733322 100644 --- a/tests/BrowserTests.php +++ b/tests/BrowserTests.php @@ -336,6 +336,18 @@ public function link_action(): void ; } + /** + * @test + */ + public function click_on_element(): void + { + $this->browser() + ->visit('/page1') + ->click('#link a') + ->assertOn('/page2') + ; + } + /** * @test */