geckodriver icon indicating copy to clipboard operation
geckodriver copied to clipboard

unhandledPromptBehavior capability is not honored

Open barancev opened this issue 9 years ago • 24 comments

Firefox Version

55.0a1 (2017-04-06) (64-bit) geckodriver 0.15

Platform

Windows 7

Steps to reproduce

Try to set this capability and execute any command while an alert is opened. It's expected that the alert will be automatically accepted or dismissed, but it does not happen.

barancev avatar Apr 07 '17 21:04 barancev

Thanks for the bug report. unhandledPromptBehavior and the unhandled prompt handler isn’t implemented in Marionette at all.

andreastt avatar Apr 07 '17 21:04 andreastt

The bug Andreas is referring to here is https://bugzilla.mozilla.org/show_bug.cgi?id=1279211.

whimboo avatar Apr 12 '17 11:04 whimboo

@andreastt Is there a plan unhandledPromptBehavior will be implemented so that the JS alert handling will be the same as legacy Firefox? As for now, if a JS alert prompted, geckodriver will depress it without throwing an UnhandledAlertException as before.

bswhb avatar Apr 28 '17 04:04 bswhb

@bswhb with bug 1359004 being fixed 2 days ago for Firefox Nightly we at least return the Error now. For closing it automatically we would still have to work on the bug I mentioned before.

whimboo avatar Apr 28 '17 08:04 whimboo

I have similar if not same issue if I set

capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);

This will produce

org.openqa.selenium.InvalidArgumentException: unhandledPromptBehavior was not a the name of a known capability or a valid extension capability

schmidtkp avatar May 03 '17 13:05 schmidtkp

As I say in https://github.com/mozilla/geckodriver/issues/617#issuecomment-292658271, the unhandledPromptBehavior capability has not been implemented yet. You can track the work on this in https://bugzilla.mozilla.org/show_bug.cgi?id=1264259.

andreastt avatar May 03 '17 14:05 andreastt

I am facing the same problem, when I migrate the code to use GeckoDriver.

Java:

String firefoxVersion = "55", FF_DriverPack = "v0.19.0";
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, 
                                          UnexpectedAlertBehaviour.IGNORE);

Exception:

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: 
	ignore was not a valid unhandledPromptBehavior value
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'

Yash-777 avatar Sep 21 '17 14:09 Yash-777

It seems that with Firefox 59 the default behavior changed from ignore to dismiss.

When specifying the capability CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR still there is an org.openqa.selenium.InvalidArgumentException exception thrown.

Our scripts depend on the ignore behavior so it would be important to have the UNEXPECTED_ALERT_BEHAVIOUR capability.

codingphil avatar Mar 19 '18 10:03 codingphil

Yes, keen observation @codingphil. We changed Firefox to match the default behaviour of IEDriver in 59.

Unfortunately we do still not support implement the user prompt handler and the unhandledPromptBehavior capability.

andreastt avatar Mar 19 '18 11:03 andreastt

Is there any expected date to get UNEXPECTED_ALERT_BEHAVIOUR supported by Firefox Capabilities or by Firefox Options? Thanks.

rahmansa2010 avatar May 22 '18 13:05 rahmansa2010

Could you please provide a way to set UNEXPECTED_ALERT_BEHAVIOUR capability as ignore.

Caused by: org.openqa.selenium.InvalidArgumentException: ignore was not a valid unhandledPromptBehavior value.

chamara-madusanka avatar May 30 '18 11:05 chamara-madusanka

Tried setting capabilities, but it didn't work. Can you please provide some suggestions to ignore closing the alerts when unhandled exception is thrown? Thanks

sajithatharaka avatar May 30 '18 12:05 sajithatharaka

Dismiss is poor default behavior for testing purposes. Target site requires me to accept an alert to complete an operation - dismiss cancels said operation. This is going to be the most common pattern for confirm() dialogs. While dismiss might be acceptable for alert(), where dismiss and accept would have similar results, it feels wrong that this was chosen as the default for confirm() dialogs as well.

Really, it should go back to ignore as the default setting. The user should be forced to choose whether to confirm or cancel the operation.

IEDriver should have matched Firefox, not the other way around.

Besides my opinions on what the default values should be, enabling setting of the behavior would at least provide a workaround. (Chrome seems to still be using "ignore" as the default behavior on all prompts)

saluk avatar Jun 12 '18 21:06 saluk

I'm currently working on the implementation of unhandledPromptBehavior support. Please note that before we can add it in Firefox/Marionette, a new geckodriver release is necessary which will include https://bugzilla.mozilla.org/show_bug.cgi?id=1468185. Soon this is out it shouldn't take that long to have it available in Firefox Nightly.

whimboo avatar Jun 13 '18 22:06 whimboo

I take geckodriver-v0.21.0-win64.zip (rel note - The unhandledPromptBehavior capability now accepts accept and notify, dismiss and notify, and ignore options.) and firefox nightly 63.0a1 (2018-08-18) (64-bit) (https://bugzilla.mozilla.org/show_bug.cgi?id=1264259 should already include in this release?) and try following code on java (selenium 3.14.0):

FirefoxOptions options = new FirefoxOptions();

options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE) options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); options.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);

or

options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY); options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY); options.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY);

but it is not working. Firefox close alert silently.

kovalev007 avatar Aug 18 '18 14:08 kovalev007

Sorry I forgot to close this issue given that this capability is now available starting with Firefox 63 which is currently the Nightly build. We are not going to uplift this to Firefox 62, so it will ride the trains. If you need this capability you will have to make use of the Nightly build.

whimboo avatar Aug 22 '18 10:08 whimboo

It is not working for me. geckodriver-v0.21.0-win64.zip and firefox nightly 63.0a1 (2018-08-18) (64-bit). See previous comment.

kovalev007 avatar Aug 22 '18 13:08 kovalev007

@kovalev007 I'm sure the capability isn't correctly passed to geckodriver. Please attach a trace log so we can verify that. See https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/TraceLogs.html in how to do that.

whimboo avatar Aug 22 '18 20:08 whimboo

I investigated my problem. It is related with onbeforeunload event. In our web application there is window.onbeforeunload with promt when user close window.

When I start firefox manually and open about:config and search dom.disable_beforeunload dom.disable_beforeunload = false in firefox 61, 62 beta and 63 nightly. it is value by default.

But when I run test with geckodriver 0.21.0 and firefox 63 nightly and open about:config dom.disable_beforeunload = true it is changed value.

Why dom.disable_beforeunload is changed?

If I write FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("dom.disable_beforeunload", false); all will be working correctly.

kovalev007 avatar Aug 23 '18 04:08 kovalev007

Additional info: geckodriver 0.21.0 and firefox 60 = working correctly = dom.disable_beforeunload = false geckodriver 0.21.0 and firefox 61 = working not correctly = dom.disable_beforeunload = true geckodriver 0.21.0 and firefox 62beta = working not correctly = dom.disable_beforeunload = true geckodriver 0.21.0 and firefox 63nightly = working not correctly = dom.disable_beforeunload = true

kovalev007 avatar Aug 23 '18 05:08 kovalev007