Selenium Python getting around "Open <...>.app?"

Viewed 1154

I am trying to write e2e tests for a Slack bot and while logging in via browser it always asks whether I'd like to use the Slack desktop app instead of continuing with the browser (its Chrome by the way). Steps the Selenium webdriver is performing:

  1. Visit https://company-name.slack.com
  2. Fill in the email and password
  3. Click Sign In button
  4. Then this shows up:

Open Slack.app Pop-Up

This is not a normal browser alert but I'd like to get rid of it. I have tried the following:

  1. webdriver.switch_to.alert.dismiss() Does not dismiss this pop-up
  2. Adding the chrome_options.add_argument('--disable-default-apps') switch also doesn't prevent the pop-up from showing
  3. Have tried the headless version as well, test failure suggests that the pop-up interrupted the flow.

This also has to work on CI servers so please if the solution didn't involve modifying developer machine then that would be wonderful.

4 Answers

Well, this is not an answer but a workaround. I managed to get around the default-app pop-up by continuing my operations in a new tab (But not before checking whether there is a pop-up in the first place). Psuedo code:

try
    find_element_by_whatever(element_you_expect_after_login)
catch TimeoutException
    webdriver.execute_script('window.open()')
    webdriver.switch_to.window(webdriver.window_handles[1])
    webdriver.get(url_which_required_login_in_the_first_place)

today I solved this problem, you can just simply install pynput module, after that :

from pynput.keyboard import Key, Controller
keyboard = Controller()

keyboard.press(Key.enter)
keyboard.release(Key.enter)

you can handle the open app popup in selenium with your keyboard.

try this chrome_options.add_argument("--disable-notifications") or chrome_options.add_argument("--disable-popup-window") or create a code for click the cancel button to do the next operation.

If this alert pops up every time you run the test, and the Cancel button is always in focus, then you can try to send the driver an ENTER.

Related