0

I have upgraded my Selenium framework to the latest version. During execution of the code, I receive the following exception

Exception:

org.openqa.selenium.InvalidArgumentException: 
Invalid capabilities in alwaysMatch: unhandledPromptBehavior is type boolean instead of string

Details :

Selenium: 3.7.1 IE : 3.7.0 (32 Bit Driver) java.version: '1.8.0_144'

Automation code works with my older IE Driver (32 Bit) - 3.4.0.

Please suggest your view to resolve the error .

capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR" ,false);
                    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
                    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
                    capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true);
                    capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
                    capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true);
                    capabilities.setCapability("nativeEvents", false);
                    capabilities.setCapability("requireWindowFocus", false);
                    capabilities.setJavascriptEnabled(true);
                    capabilities.setCapability("ignoreProtectedModeSettings", true);
                    System.setProperty("webdriver.ie.driver", ieExe.getAbsolutePath());
                    opt = new InternetExplorerOptions();
                    opt.merge(capabilities);
                    driver = new InternetExplorerDriver(opt);
                    driver.manage().deleteAllCookies();
driver.manage().window().maximize();
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Priya
  • 69
  • 3
  • 14

4 Answers4

3

In short:

  • Valid capability name is: "unhandledPromptBehavior"
  • Valid values for "unhandledPromptBehavior" AND for "unexpectedAlertBehavior" are: "accept", "dismiss", "accept and notify", "dismiss and notify", "ignore". But W3C supports only 1st and 2nd.

In details:

UNHANDLED_PROMPT_BEHAVIOUR is a constant name from CapabilityType interface. But you use it as string. So either capabilities.setCapability("unhandledPromptBehavior", ...) or capabilities.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, ...)

Values for those capabilities are encauntered in enum org.openqa.selenium.UnexpectedAlertBehaviour: it is because unhandledPromptBehavior is new updated name for unexpectedAlertBehaviour in webdriver3. Actually when you set unexpectedAlertBehaviour the webdriver (v3.8) automatically set both values.

So root cause of your error is the line: capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true):

You should replace true to valid value (see above). This line actually set both capabilities: unhandledPromptBehavior and unexpectedAlertBehaviour. Your first line (with "UNHANDLED_PROMPT_BEHAVIOR") just ignored by driver.

1

I was able to resolve the issue with below change "capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, UnexpectedAlertBehaviour.IGNORE);"

Priya
  • 69
  • 3
  • 14
0

The error InvalidArgumentException: Invalid capabilities in alwaysMatch: unhandledPromptBehavior is type boolean instead of string Details says does speaks about the main issue.

As you mentioned IE Driver so I guess the issue is with Internet Explorer and IEDriverServer.exe. To over come the issue use setCapability("UNHANDLED_PROMPT_BEHAVIOUR", "accept") as per the following code block :

System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR", "accept");
InternetExplorerOptions opt = new InternetExplorerOptions();
opt.merge(capabilities);
WebDriver driver = new InternetExplorerDriver(opt);
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • I tried the same and its still showing the same error. – Priya Nov 22 '17 at 05:49
  • Try changing it to `"UNHANDLED_PROMPT_BEHAVIOUR", false` – DebanjanB Nov 22 '17 at 05:51
  • Still getting same error : [ERROR] 2017-11-22 11:36:41.384 [main] DetailedLogs - Error : >>>>>Class Keywords | Method setupBrowser | Exception desc : Invalid capabilities in alwaysMatch: unhandledPromptBehavior is type boolean instead of string Build info: version: '3.7.0', revision: '2321c73', time: '2017-11-02T22:22:35.584Z' System info: host: 'EQ-EQ6338424', ip: '10.238.214.158', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144' Driver info: driver.version: InternetExplorerDriver – Priya Nov 22 '17 at 06:07
  • Even I modifed code as you mentioned capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR" ,false); – Priya Nov 22 '17 at 06:08
  • Try this : `capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR", Boolean.parseBoolean("true"));` and `capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR", Boolean.parseBoolean("false"));` – DebanjanB Nov 22 '17 at 06:23
  • Same error. I modified my code as below capabilities.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, Boolean.parseBoolean("true")); capabilities.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, Boolean.parseBoolean("false")); – Priya Nov 22 '17 at 06:39
  • Last try - `capabilities.setCapability("UNHANDLED_PROMPT_BEHAVIOUR", Boolean.valueOf("true"));` – DebanjanB Nov 22 '17 at 06:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159548/discussion-between-priya-and-debanjanb). – Priya Nov 22 '17 at 07:06
  • Check out my updated Answer and let me know the status – DebanjanB Nov 22 '17 at 08:18
  • Still I am facing the same issue – Priya Nov 23 '17 at 06:45
0

Note : FirefoxDriver(Capabilities desiredCapabilities), this constructor is Deprecated in selenium 3.141.0 (i am taking about 3.141.0 onwards) so you can not pass Capabilities class object to webDriver constructor. to pass Capabilities functionality to webDriver constructor use FirefoxOptions class object and pass its object to WebDriver constructor.

FirefoxOptions options = new FirefoxOptions();
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
WebDriver driver = new FirefoxDriver(options);
System.setProperty("webdriver.gecko.driver", "path-to gecko-driver");
driver.get("url");
Alert alert=driver.switchTo().alert();
 driver.findElement(By.id("username")).sendKeys("username");
 driver.findElement(By.id("password")).sendKeys("Pwd");
 driver.switchTo().alert().accept();
 driver.switchTo().defaultContent();
rajat
  • 1
  • 1