How to click on open application alert using Selenium

Question:

I am trying to click on open application alert using Selenium, and I am getting this error

NoAlertPresentException: Message: no such alert

So basically I am trying to open zoom application from the browser

enter image description here

And here is my code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

driver = webdriver.Chrome(executable_path='chromedriver/chromedriver')
driver.get("https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09")

try:
    WebDriverWait(driver, 5).until(EC.alert_is_present(), 'Timed out waiting for alerts to appear')
    alert = driver.switch_to.alert
    alert.accept()
    print("alert accepted")
except TimeoutException:
    print("no alert")
Asked By: abu8na9

||

Answers:

Because this is not a browser Alert, rather OS App selector, you cannot interact with it within Selenium.

See: Selenium C# How to handle Alert "Open Pick an app"?

You can prevent these App selectors by default by using the --disable-default-apps flag when starting up Chrome.

Answered By: NetworkMeister

Thanks to NetworkMeister, I end up using default app method, Like the following:

1- Open Firefox and go to zoom URL, when Launch application appear choose zoom and click on remember my choice and click open link

2- Go to firefox and paste this about:support then search for Profile Folder and copy the path

3- Go to your code and add profile parameter to selenium driver and use the path you have copied

fp = webdriver.FirefoxProfile('C:/Users/ASUS//AppData/Roaming/Mozilla/Firefox/Profiles/0rgewd47.default-release')
driver = webdriver.Firefox(executable_path='geckodriver', firefox_profile=fp)
driver.get('https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09')

Now zoom application will open automatically when you execute this code


Note: Firefox profile contains all of your browsing data, If you want to share your code I suggest creating a new Firefox profile, For more information look here

Answered By: abu8na9

I encountered this problem my self.
Apparently this is related to the alert being OS level rather than being at a browser level.
The simplest solution I found is https://pypi.org/project/PyAutoGUI/ which allows you to pass an img of the button you want to click and then it locates it on the screen. You can call python directly from java.
Native java solution: https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
this allows you to automate stuff like "move mouse to position" -> "mouse click" etc.

EDIT: the main downside is that the webdriver cannot be run in headless mode as PyAutoGUI makes a screenshot of the screen to locate the button.

Answered By: fedmag

From what I noticed is that when you open any such link in the browser the URL changes a bit. With this you can figure out the link for opening it in the browser. For example I have this zoom meeting

https://us04web.zoom.us/ w/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09

Now this would open a popup like you showed in the browser. (This link is not real. I changed 2-3 characters in the URL for security reasons). But now if you try this link

https://us04web.zoom.us/ wc/join/ 76919011107?tk=5Q_zikLZhvWlqc_nzVcYaHoTyo7JuDY6cvLB9y9t0zc.DQIAAAARDLr3IxZHM21mSHFzYlR6Q0xZdnNhcnUwbUV3AAAAAAAAAAAAAAAAAAAAAAAAAAAA&pwd=QANkcTdsNlpjYWY4czZvd3FHV0NLQT09

This will directly open the meeting in the browser. Note the change in URL has been shown in bold (I had to add spaces because of that on both sides). Now this may change over time but fundamentally by comparing the 2 links you should find a way to achieve this.

Similarly for Microsoft Teams if you add "_#" after the domain you can join the meeting through the browser

For example if I want to open this link in the browser

https://teams.microsoft.com/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d

I’ll have to write

https://teams.microsoft.com/_#/l/meetup-join/19%3ameeting_NTRlM2JiZWUtZjNiMC00ZjVhLTlmMWEtZDcxYjBmYjdhY2Nl%40thread.v2/0?context=%7b%22Tid%22%3a%22e85f2c00-2730-4ca5-b8d8-609b15bd4746%22%2c%22Oid%22%3a%223bf1c992-96b1-4a87-808f-dcc5bb2009c9%22%7d

These patterns can be found by observing the link before and after opening it in the browser.

Answered By: Joel

This is not the best way but I resolved the issue by sending keyboard commands. It works on Windows, I haven’t tested on different os.

import pyautogui

sleep(3)                           # sleep until pop up shown
pyautogui.press('tab', presses=2)  # navigate to open button
pyautogui.press('enter')           # open application
Answered By: Furkan

For me using Robot class worked for teams.

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
Answered By: Anil Shrestha

For Edge Driver, here is the way to handle it by using the profile:

Find your profile path:

In Edge, go to edge://version -> Profile path
It should be something like this: C:Users[username]AppDataLocalMicrosoftEdgeUser Datadefault[profile name]

Create selenium options to use the profile

myoptions = webdriver.EdgeOptions()
myoptions.add_argument(r"user-data-dir=C:Users[username]AppDataLocalMicrosoftEdgeUser DataDefault")
myoptions.add_argument("profile-directory=[profile name]")
driver = webdriver.Edge(executable_path=r"[path_to_edge_driver]msedgedriver.exe",options=myoptions)
driver.get('https://zoom.us/j/93459172503?pwd=QkhnMEQ0ZTRZd0grUVJkT2NudmlFZz09')
Answered By: Johnny.X