Skip to content

Find button by text exactly #1162

Open
Open
@Barbapapazes

Description

@Barbapapazes

Dusk Version

8.x

Laravel Version

11.x

PHP Version

8.4

PHPUnit Version

10.x

Database Driver & Version

/

Description

Hello 👋,

The method pressAndWaitFor uses the method findButtonByText (

/**
* Resolve the element for a given button by text.
*
* @param string $button
* @return \Facebook\WebDriver\Remote\RemoteWebElement|null
*/
protected function findButtonByText($button)
{
foreach ($this->all('button') as $element) {
if (Str::contains($element->getText(), $button)) {
return $element;
}
}
}
) that does not try to resolve the button with exactly its name but with a name that contains the parameter. This is an issue when there is multiple button on the page.

For example, you can have the button Create Application and another button Create but you won't be able to target Create because Create Application will always be resolved first (if it appears fist in the DOM).

Steps To Reproduce

  1. Create a button Create Application
  2. Create a button Create
  3. Try to use the method pressAndWaitFor to select the Create but Dusk will try to press Create Application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions