Behat / MinkExtension

Mink extension (tight integration and configuration) for Behat
MIT License
636 stars 279 forks source link

Press-button step clicks hidden button, even when there is a visible match #280

Open BevanR opened 7 years ago

BevanR commented 7 years ago

MinkContext->pressButton() presses the first button in the DOM that matches, even if that button is not visible, and there is another matching button that is visible.

This scenario is a likely with modal dialog libraries that preload dialog HTML into the DOM (to have dialogs appear faster when they are called upon). If there are multiple confirmation dialogs that all have a "Confirm" button, there is no convenient way to specify which "Confirm" button to press. Nor is it reasonable to specify which "Confirm" button to press given that only one is visible at a time.

Could MinkContext/Behat be smarter about selecting which element to click when there are multiple options but some are not visible? Would a pull request be welcome? Can you suggest how you would prefer it is implemented?

spolischook commented 7 years ago

I think some driver can press button even if it not visible, e.g. BrowserKitDriver

glennmcewan commented 7 years ago

Mink cannot know which button you intend to press if multiple have the same name. What if both are visible? In your case, only one is visible. As @spolischook has mentioned, some drivers do not have a concept of visibility (BrowserKitDriver cannot, Selenium can).

In this instance -- attempting to click a button in the currently opened modal -- it would make sense to use the find method and click methods:

$this->getSession()->getPage()->find('.modal--active .confirm-btn')->click();

So first find the active modal, and then the desired button within it.

Not all drivers can tell Mink if an element is visible, which makes this quite tricky. This would still be an issue if you were using Selenium on its own (you would need to find all buttons matching 'Confirm', loop them, and click the one which is visible).