MinkExtension icon indicating copy to clipboard operation
MinkExtension copied to clipboard

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

Open BevanR opened this issue 7 years ago • 2 comments

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?

BevanR avatar May 01 '17 06:05 BevanR

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

spolischook avatar May 02 '17 10:05 spolischook

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).

glennmcewan avatar May 17 '17 15:05 glennmcewan