Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/BrowserTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down