6

I have a Selenium test, in which I need to click on a "cliclient://" link, and that link needs to open an application. Now, I need to create a new profile for each test, and I don't know how to bypass the "Launch Application" dialog that appears when clicking on the link:

enter image description here

Here's a snippet of the test that I've created:

    profile = Selenium::WebDriver::Firefox::Profile.new

    profile.secure_ssl = false
    profile.assume_untrusted_certificate_issuer=true

    profile["plugin.default.state"] = 2
    profile["plugin.state.java"] = 2

    profile["browser.download.folderList"] = 2
    profile["browser.download.manager.alertOnEXEOpen"] = false
    profile["browser.download.manager.closeWhenDone"] = true
    profile["browser.download.manager.focusWhenStarting"] = false
    profile["browser.download.manager.showWhenStarting"] = false
    profile["browser.helperApps.alwaysAsk.force"] = false
    profile["browser.helperApps.neverAsk.saveToDisk"] = 'application/x-msdownload,application/octet-stream, application/x-msdownload, application/exe, application/x-exe, application/dos-exe, vms/exe, application/x-winexe, application/msdos-windows, application/x-msdos-program'

    profile["gfx.direct2d.disabled"] = true
    profile["layers.acceleration.disabled"] = true

What is it in the profile that I need to set, to bypass the dialog, or to somehow click on OK when this dialog appears?

acikojevic
  • 915
  • 1
  • 7
  • 16
  • hey, could you help me bit clearly, what you are trying to achieve here, do you want to disable alerts in profile or need to handle this alert? – murali selenium Mar 21 '17 at 15:22
  • Either one suits for me. If this can be disabled through some profile setting, that would be great. If not, then I'll need a way to handle the alert. – Zoran Trifunovski Mar 21 '17 at 15:25

3 Answers3

1

You can also try using SikuliX http://sikulix.com/ which is an automation software which uses images to recognise the GUI elements on which certain actions need to be performed

Hovever to use it with ruby you will most probably need to compile and run a java class via a system command and also you will need JDK installed on the machine where the automation will be performed

Inquisitive
  • 386
  • 2
  • 5
1

The idea is creating a profile with default schemes you want and let selenium initialize by copying this profile. The key file that contains default schemes is handlers.json rather than prefs.js

Below is the proof of concept in python.

import json
import os
from pathlib import Path

from selenium import webdriver

# %APPDATA%\Mozilla\Firefox\Profiles\oa6m3bc6.default\Preferences\handlers.json
SCHEME_NAME = 'xxxxx'
PROFILE_DIR_NAME = 'xxxxxx'

handlers = {
    'defaultHandlersVersion': {'en-US': 4},
    'schemes': {SCHEME_NAME: {'action': 4}}
}
profile_dir = Path(os.environ['APPDATA']) / f'Mozilla/Firefox/Profiles/{PROFILE_DIR_NAME}'
profile_dir.mkdir(exist_ok=True)
with open(profile_dir / 'handlers.json', 'w+') as f:
    json.dump(handlers, f)
profile = webdriver.FirefoxProfile(profile_dir)
driver = webdriver.Firefox(profile)
driver.get('http://example.com/')

Tested with Firefox 71.0, geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000), Python 3.7, and Windows 10

C.W.
  • 452
  • 1
  • 10
  • 15
0

Use C# to access the Win32 API and find the handle of the window with the title "Launch Application'. You'll need to use this, as the window is controlled by the OS and therefore Selenium can't interact with it. Then use the same API to click the cancel button (find its identifying properties using WinSpy)

Sorry if this isn't a full answer but I couldn't merely comment as I have insufficient rep at the moment.

Community
  • 1
  • 1
hjr2000
  • 143
  • 1
  • 10